Skip to content

Commit 99fab50

Browse files
cezaraugustobsclifton
authored andcommitted
Merge pull request #4239 from brave/ca-6941
Modify Sync UI to allow only one device in chain
1 parent cf539a5 commit 99fab50

File tree

7 files changed

+48
-140
lines changed

7 files changed

+48
-140
lines changed

components/brave_sync/brave_profile_sync_service_impl.cc

+1-5
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,7 @@ void BraveProfileSyncServiceImpl::GetSettingsAndDevices(
327327
void BraveProfileSyncServiceImpl::GetSyncWords() {
328328
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
329329
Uint8Array seed = Uint8ArrayFromString(brave_sync_prefs_->GetSeed());
330-
if (!seed.empty()) {
331-
NotifyHaveSyncWords(crypto::PassphraseFromBytes32(seed));
332-
} else {
333-
NotifyHaveSyncWords("TEST DEBUG");
334-
}
330+
NotifyHaveSyncWords(crypto::PassphraseFromBytes32(seed));
335331
}
336332

337333
std::string BraveProfileSyncServiceImpl::GetSeed() {

components/brave_sync/ui/components/commonDialogs/cancelDeviceSyncing.tsx

-36
This file was deleted.

components/brave_sync/ui/components/disabledContent.tsx

+13-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as React from 'react'
66

77
// Components
88
import { Button } from 'brave-ui'
9+
import { LoaderIcon } from 'brave-ui/components/icons'
910

1011
// Component-specific components
1112
import {
@@ -22,7 +23,6 @@ import {
2223
import { SyncStartIcon } from 'brave-ui/features/sync/images'
2324

2425
// Modals
25-
import DeviceTypeModal from './modals/deviceType'
2626
import EnterSyncCodeModal from './modals/enterSyncCode'
2727

2828
// Utils
@@ -49,6 +49,12 @@ export default class SyncDisabledContent extends React.PureComponent<Props, Stat
4949

5050
onClickNewSyncChainButton = () => {
5151
this.setState({ newToSync: !this.state.newToSync })
52+
// once the screen is rendered, create a sync chain.
53+
// this allow us to request the qr code and sync words immediately
54+
const { thisDeviceName } = this.props.syncData
55+
if (thisDeviceName === '') {
56+
this.props.actions.onSetupNewToSync('')
57+
}
5258
}
5359

5460
onClickEnterSyncChainCodeButton = () => {
@@ -66,11 +72,6 @@ export default class SyncDisabledContent extends React.PureComponent<Props, Stat
6672
return (
6773
<DisabledContent>
6874
<Main>
69-
{
70-
newToSync
71-
? <DeviceTypeModal syncData={syncData} actions={actions} onClose={this.onClickNewSyncChainButton} />
72-
: null
73-
}
7475
{
7576
existingSyncCode
7677
? <EnterSyncCodeModal syncData={syncData} actions={actions} onClose={this.onClickEnterSyncChainCodeButton} />
@@ -89,6 +90,12 @@ export default class SyncDisabledContent extends React.PureComponent<Props, Stat
8990
type='accent'
9091
onClick={this.onClickNewSyncChainButton}
9192
text={getLocale('startSyncChain')}
93+
icon={{
94+
position: 'before',
95+
image: newToSync === true
96+
? <LoaderIcon />
97+
: null
98+
}}
9299
/>
93100
<Button
94101
level='secondary'

components/brave_sync/ui/components/enabledContent.tsx

+24
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,30 @@ export default class SyncEnabledContent extends React.PureComponent<Props, State
7070
}
7171
}
7272

73+
componentDidMount () {
74+
this.shouldShowAddDeviceModal()
75+
}
76+
77+
componentDidUpdate (prevProps: Props) {
78+
if (
79+
prevProps.syncData.devices.length !==
80+
this.props.syncData.devices.length
81+
) {
82+
// if devices length changed, users either added
83+
// or removed a device. again, check if they are less than 2
84+
// so we can remind them again to add a new device
85+
this.shouldShowAddDeviceModal()
86+
}
87+
}
88+
89+
shouldShowAddDeviceModal = () => {
90+
const { syncData } = this.props
91+
const hasLessThanTwoDevices: boolean = syncData.devices.length < 2
92+
// if only one device is found, remind the user
93+
// at every page refresh to add a new device
94+
this.setState({ addDevice: hasLessThanTwoDevices })
95+
}
96+
7397
getDevicesRows = (devices?: any): Row[] | undefined => {
7498
if (!devices) {
7599
return

components/brave_sync/ui/components/modals/deviceType.tsx

-9
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,6 @@ export default class DeviceTypeModal extends React.PureComponent<Props, State> {
4848
}
4949
}
5050

51-
componentDidMount () {
52-
// once the screen is rendered, create a sync chain.
53-
// this allow us to request the qr code and sync words immediately
54-
const { thisDeviceName } = this.props.syncData
55-
if (thisDeviceName === '') {
56-
this.props.actions.onSetupNewToSync('')
57-
}
58-
}
59-
6051
onUserNoticedError = () => {
6152
this.props.actions.clearSyncSetupError()
6253
this.props.onClose()

components/brave_sync/ui/components/modals/scanCode.tsx

+5-42
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ import {
1919
Link
2020
} from 'brave-ui/features/sync'
2121

22-
// Dialogs
23-
import CancelDeviceSyncingDialog from '../commonDialogs/cancelDeviceSyncing'
24-
2522
// Utils
2623
import { getLocale } from '../../../../common/locale'
2724

@@ -37,15 +34,13 @@ interface Props {
3734
}
3835

3936
interface State {
40-
willCancelScanCode: boolean
4137
newDeviceFound: boolean
4238
}
4339

4440
export default class ScanCodeModal extends React.PureComponent<Props, State> {
4541
constructor (props: Props) {
4642
super(props)
4743
this.state = {
48-
willCancelScanCode: false,
4944
newDeviceFound: false
5045
}
5146
}
@@ -61,11 +56,11 @@ export default class ScanCodeModal extends React.PureComponent<Props, State> {
6156
const { newDeviceFound } = this.state
6257
// when a device is found, self-close all modals
6358
if (newDeviceFound) {
64-
this.dismissAllModals()
59+
this.onDismissAllModals()
6560
}
6661
}
6762

68-
dismissAllModals = () => {
63+
onDismissAllModals = () => {
6964
this.props.onClose()
7065
if (this.props.onCloseDeviceTypeModal) {
7166
this.props.onCloseDeviceTypeModal()
@@ -76,44 +71,12 @@ export default class ScanCodeModal extends React.PureComponent<Props, State> {
7671
this.props.onClickViewSyncCodeInstead()
7772
}
7873

79-
onDismissModal = () => {
80-
const { isSyncConfigured } = this.props.syncData
81-
// if user is still trying to build a sync chain,
82-
// open the confirmation modal. otherwise close it
83-
isSyncConfigured
84-
? this.setState({ willCancelScanCode: true })
85-
: this.dismissAllModals()
86-
}
87-
88-
onDismissDialog = () => {
89-
this.setState({ willCancelScanCode: false })
90-
}
91-
92-
onConfirmDismissModal = () => {
93-
const { isSyncConfigured } = this.props.syncData
94-
// sync is enabled when at least 2 devices are in the chain.
95-
// this modal works both with sync enabled and disabled states.
96-
// in case user opens it in the enabled content screen,
97-
// check there are 2 devices in chain before reset
98-
if (isSyncConfigured) {
99-
this.props.actions.onSyncReset()
100-
this.dismissAllModals()
101-
}
102-
this.setState({ willCancelScanCode: false })
103-
this.props.onClose()
104-
}
105-
10674
render () {
10775
const { syncData } = this.props
108-
const { willCancelScanCode, newDeviceFound } = this.state
76+
const { newDeviceFound } = this.state
10977

11078
return (
11179
<Modal id='scanCodeModal' displayCloseButton={false} size='small'>
112-
{
113-
willCancelScanCode
114-
? <CancelDeviceSyncingDialog onClickCancel={this.onDismissDialog} onClickOk={this.onConfirmDismissModal} />
115-
: null
116-
}
11780
<ModalHeader>
11881
<div>
11982
<Title level={1}>{getLocale('scanThisCode')}</Title>
@@ -132,7 +95,7 @@ export default class ScanCodeModal extends React.PureComponent<Props, State> {
13295
</ScanGrid>
13396
<ThreeColumnButtonGrid>
13497
<div>
135-
<Link onClick={this.onDismissModal}>{getLocale('cancel')}</Link>
98+
<Link onClick={this.onDismissAllModals}>{getLocale('cancel')}</Link>
13699
</div>
137100
<div>
138101
<Button
@@ -148,7 +111,7 @@ export default class ScanCodeModal extends React.PureComponent<Props, State> {
148111
level='primary'
149112
type='accent'
150113
size='medium'
151-
onClick={this.onDismissModal}
114+
onClick={this.onDismissAllModals}
152115
disabled={newDeviceFound === false}
153116
text={
154117
newDeviceFound === false

components/brave_sync/ui/components/modals/viewSyncCode.tsx

+5-42
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ import {
1818
Link
1919
} from 'brave-ui/features/sync'
2020

21-
// Dialogs
22-
import CancelDeviceSyncingDialog from '../commonDialogs/cancelDeviceSyncing'
23-
2421
// Utils
2522
import { getLocale } from '../../../../common/locale'
2623

@@ -33,15 +30,13 @@ interface Props {
3330
}
3431

3532
interface State {
36-
willCancelViewCode: boolean
3733
newDeviceFound: boolean
3834
}
3935

4036
export default class ViewSyncCodeModal extends React.PureComponent<Props, State> {
4137
constructor (props: Props) {
4238
super(props)
4339
this.state = {
44-
willCancelViewCode: false,
4540
newDeviceFound: false
4641
}
4742
}
@@ -57,11 +52,11 @@ export default class ViewSyncCodeModal extends React.PureComponent<Props, State>
5752
const { newDeviceFound } = this.state
5853
// when a device is found, self-close this modal
5954
if (newDeviceFound) {
60-
this.dismissAllModals()
55+
this.onDismissAllModals()
6156
}
6257
}
6358

64-
dismissAllModals = () => {
59+
onDismissAllModals = () => {
6560
this.props.onClose()
6661
if (this.props.onCloseDeviceTypeModal) {
6762
this.props.onCloseDeviceTypeModal()
@@ -72,44 +67,12 @@ export default class ViewSyncCodeModal extends React.PureComponent<Props, State>
7267
this.props.onClickScanCodeInstead()
7368
}
7469

75-
onDismissModal = () => {
76-
const { isSyncConfigured } = this.props.syncData
77-
// if user is still trying to build a sync chain,
78-
// open the confirmation modal. otherwise close it
79-
isSyncConfigured
80-
? this.setState({ willCancelViewCode: true })
81-
: this.dismissAllModals()
82-
}
83-
84-
onDismissDialog = () => {
85-
this.setState({ willCancelViewCode: false })
86-
}
87-
88-
onConfirmDismissModal = () => {
89-
const { isSyncConfigured } = this.props.syncData
90-
// sync is enabled when at least 2 devices are in the chain.
91-
// this modal works both with sync enabled and disabled states.
92-
// in case user opens it in the enabled content screen,
93-
// check there are 2 devices in chain before reset
94-
if (isSyncConfigured) {
95-
this.props.actions.onSyncReset()
96-
this.dismissAllModals()
97-
}
98-
this.setState({ willCancelViewCode: false })
99-
this.props.onClose()
100-
}
101-
10270
render () {
10371
const { syncData } = this.props
104-
const { willCancelViewCode, newDeviceFound } = this.state
72+
const { newDeviceFound } = this.state
10573

10674
return (
10775
<Modal id='viewSyncCodeModal' displayCloseButton={false} size='small'>
108-
{
109-
willCancelViewCode
110-
? <CancelDeviceSyncingDialog onClickCancel={this.onDismissDialog} onClickOk={this.onConfirmDismissModal} />
111-
: null
112-
}
11376
<ModalHeader>
11477
<div>
11578
<Title level={1}>{getLocale('chainCode')}</Title>
@@ -132,7 +95,7 @@ export default class ViewSyncCodeModal extends React.PureComponent<Props, State>
13295
}
13396
<ThreeColumnButtonGrid>
13497
<div>
135-
<Link onClick={this.onDismissModal}>{getLocale('cancel')}</Link>
98+
<Link onClick={this.onDismissAllModals}>{getLocale('cancel')}</Link>
13699
</div>
137100
<div>
138101
<Button
@@ -147,7 +110,7 @@ export default class ViewSyncCodeModal extends React.PureComponent<Props, State>
147110
level='primary'
148111
type='accent'
149112
size='medium'
150-
onClick={this.onDismissModal}
113+
onClick={this.onDismissAllModals}
151114
disabled={newDeviceFound === false}
152115
text={
153116
newDeviceFound === false

0 commit comments

Comments
 (0)