From 76c32928fe9dd803933ce05c716d68f99eabeddb Mon Sep 17 00:00:00 2001 From: Cezar Augusto Date: Mon, 31 Dec 2018 14:53:16 -0200 Subject: [PATCH] refactor modals to use store instead of state in Sync fix https://github.com/brave/brave-browser/issues/2677 fix https://github.com/brave/brave-browser/issues/2564 address https://github.com/brave/brave-browser/issues/2567 --- .../donate/components/siteBanner.tsx | 2 +- .../brave_sync/ui/actions/sync_actions.ts | 9 ++ components/brave_sync/ui/components/app.tsx | 53 ++++++++++++ .../ui/components/disabledContent.tsx | 57 ++++++++----- .../ui/components/enabledContent.tsx | 65 ++------------ .../ui/components/errorDialogs/initFailed.tsx | 30 +++++++ .../components/errorDialogs/missingWords.tsx | 29 +++++++ .../ui/components/errorDialogs/noInternet.tsx | 30 +++++++ .../ui/components/errorDialogs/wrongWords.tsx | 30 +++++++ .../ui/components/modals/deviceType.tsx | 84 +++---------------- .../ui/components/modals/enterSyncCode.tsx | 77 ++++++++--------- .../ui/components/modals/removeDevice.tsx | 13 +-- .../ui/components/modals/resetSync.tsx | 17 ++-- .../ui/components/modals/scanCode.tsx | 49 +++++------ .../ui/components/modals/viewSyncCode.tsx | 48 +++++------ .../brave_sync/ui/constants/sync_types.ts | 3 +- .../brave_sync/ui/reducers/sync_reducer.ts | 6 ++ components/brave_sync/ui/storage.ts | 12 ++- components/definitions/sync.d.ts | 24 ++++-- 19 files changed, 365 insertions(+), 273 deletions(-) create mode 100644 components/brave_sync/ui/components/errorDialogs/initFailed.tsx create mode 100644 components/brave_sync/ui/components/errorDialogs/missingWords.tsx create mode 100644 components/brave_sync/ui/components/errorDialogs/noInternet.tsx create mode 100644 components/brave_sync/ui/components/errorDialogs/wrongWords.tsx diff --git a/components/brave_rewards/resources/donate/components/siteBanner.tsx b/components/brave_rewards/resources/donate/components/siteBanner.tsx index 402e0f9f059f..d416f3cba54f 100644 --- a/components/brave_rewards/resources/donate/components/siteBanner.tsx +++ b/components/brave_rewards/resources/donate/components/siteBanner.tsx @@ -159,7 +159,7 @@ class Banner extends React.Component { social={this.generateSocialLinks()} showUnVerifiedNotice={!verified} learnMoreNotice={'https://brave.com/faq-rewards/#unclaimed-funds'} - addFundsLink={this.addFundsLink} + // addFundsLink={this.addFundsLink} > {description} diff --git a/components/brave_sync/ui/actions/sync_actions.ts b/components/brave_sync/ui/actions/sync_actions.ts index d74a81a12bef..747ce685f242 100644 --- a/components/brave_sync/ui/actions/sync_actions.ts +++ b/components/brave_sync/ui/actions/sync_actions.ts @@ -119,6 +119,15 @@ export const resetSyncSetupError = () => { return action(types.SYNC_RESET_SETUP_ERROR) } +/** + * Dispatches a message indicating which Sync modal should be open + * @param {Sync.ModalOptions} modalName - the modal that should be either open or closed + * @param {boolean} open - whether or not the modal should be visible to the user + */ +export const maybeOpenSyncModal = (modalName: Sync.ModalOptions, open: boolean) => { + return action(types.SYNC_MAYBE_OPEN_MODAL, { modalName, open }) +} + /** * Dispatched by the back-end to inform useful log messages for debugging purposes * @param {string} message - the log message diff --git a/components/brave_sync/ui/components/app.tsx b/components/brave_sync/ui/components/app.tsx index fa1cccd8ed96..8b40a732bb2f 100644 --- a/components/brave_sync/ui/components/app.tsx +++ b/components/brave_sync/ui/components/app.tsx @@ -10,6 +10,19 @@ import { connect } from 'react-redux' import DisabledContent from './disabledContent' import EnabledContent from './enabledContent' +// Modals +import DeviceTypeModal from './modals/deviceType' +import EnterSyncCodeModal from './modals/enterSyncCode' +import ScanCodeModal from './modals/scanCode' +import ViewSyncCodeModal from './modals/viewSyncCode' +import ResetSyncModal from './modals/resetSync' + +// Error alerts +import InitFailedDialog from './errorDialogs/initFailed' +import MissingWordsDialog from './errorDialogs/missingWords' +import NoInternetDialog from './errorDialogs/noInternet' +import WrongWordsDialog from './errorDialogs/wrongWords' + // Utils import * as syncActions from '../actions/sync_actions' @@ -29,6 +42,10 @@ export class SyncPage extends React.PureComponent { this.props.actions.onPageLoaded() } + onUserNoticedError = () => { + this.props.actions.resetSyncSetupError() + } + render () { const { syncData, actions } = this.props @@ -38,6 +55,42 @@ export class SyncPage extends React.PureComponent { return (
+ { + syncData.error === 'ERR_SYNC_WRONG_WORDS' && + + } + { + syncData.error === 'ERR_SYNC_MISSING_WORDS' && + + } + { + syncData.error === 'ERR_SYNC_NO_INTERNET' && + + } + { + syncData.error === 'ERR_SYNC_INIT_FAILED' && + + } + { + syncData.modalsOpen.deviceType && + + } + { + syncData.modalsOpen.enterSyncCode && + + } + { + syncData.modalsOpen.scanCode && + + } + { + syncData.modalsOpen.viewSyncCode && + + } + { + syncData.modalsOpen.resetSync && + + } { syncData.isSyncConfigured && syncData.devices.length > 1 ? diff --git a/components/brave_sync/ui/components/disabledContent.tsx b/components/brave_sync/ui/components/disabledContent.tsx index 3faed65cde79..62fe9e6c48de 100644 --- a/components/brave_sync/ui/components/disabledContent.tsx +++ b/components/brave_sync/ui/components/disabledContent.tsx @@ -18,11 +18,10 @@ import { DisabledContent } from 'brave-ui/features/sync' -import { SyncStartIcon } from 'brave-ui/features/sync/images' +// Icons +import { LoaderIcon } from 'brave-ui/components/icons' -// Modals -import DeviceTypeModal from './modals/deviceType' -import EnterSyncCodeModal from './modals/enterSyncCode' +import { SyncStartIcon } from 'brave-ui/features/sync/images' // Utils import { getLocale } from '../../../common/locale' @@ -33,30 +32,47 @@ interface Props { } interface State { - newToSync: boolean - existingSyncCode: boolean + willCreateNewSyncChain: boolean } export default class SyncDisabledContent extends React.PureComponent { constructor (props: Props) { super(props) - this.state = { - newToSync: false, - existingSyncCode: false + this.state = { willCreateNewSyncChain: false } + } + + componentDidUpdate (prevProps: Props) { + // creating the chain can take a while and the operation + // resets all sync states so in this case set a loading indicator + // until Sync is ready. once ready, open the proper modal + if ( + this.state.willCreateNewSyncChain === true && + prevProps.syncData.thisDeviceName !== + this.props.syncData.thisDeviceName + ) { + this.props.actions.maybeOpenSyncModal('deviceType', true) + // modal is open, reset loading state + this.setState({ willCreateNewSyncChain: false }) } } onClickNewSyncChainButton = () => { - this.setState({ newToSync: !this.state.newToSync }) + // once user clicks "start a new sync chain", create the chain + this.setState({ willCreateNewSyncChain: true }) + + const { thisDeviceName } = this.props.syncData + if (thisDeviceName === '') { + this.props.actions.onSetupNewToSync('') + } } onClickEnterSyncChainCodeButton = () => { - this.setState({ existingSyncCode: !this.state.existingSyncCode }) + this.props.actions.maybeOpenSyncModal('enterSyncCode', true) } render () { - const { actions, syncData } = this.props - const { newToSync, existingSyncCode } = this.state + const { syncData } = this.props + const { willCreateNewSyncChain } = this.state if (!syncData) { return null @@ -65,16 +81,6 @@ export default class SyncDisabledContent extends React.PureComponent
- { - newToSync - ? - : null - } - { - existingSyncCode - ? - : null - } @@ -87,6 +93,11 @@ export default class SyncDisabledContent extends React.PureComponent + }} />
-