From 7a9e28cad7321cfe5ca7749370ad578340f9ea88 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 26 Jan 2018 17:28:13 -0800 Subject: [PATCH 1/9] sign out warning, still a WIP --- lib/dialogs/settings.jsx | 57 +++++++++++++++++++++++++++++++++++++++- package.json | 12 ++++----- scss/settings.scss | 7 +++++ 3 files changed, 69 insertions(+), 7 deletions(-) diff --git a/lib/dialogs/settings.jsx b/lib/dialogs/settings.jsx index cb1c142a7..278d6fd3f 100644 --- a/lib/dialogs/settings.jsx +++ b/lib/dialogs/settings.jsx @@ -15,6 +15,12 @@ export const SettingsDialog = React.createClass({ onSignOut: PropTypes.func.isRequired, }, + getInitialState() { + return { + shouldShowSyncWarning: false, + }; + }, + onDone() { this.props.actions.closeDialog({ key: this.props.dialog.key }); }, @@ -37,6 +43,42 @@ export const SettingsDialog = React.createClass({ }); }, + // TODO: fix. + hasUnsyncedNotes: function() { + let foundUnsynced = false; + + this.props.appState.notes.some(note => { + this.props.noteBucket.getVersion(note.id, (e, version) => { + if (e || version >= 0) { + foundUnsynced = true; + } + }); + + return foundUnsynced === true; + }); + + return foundUnsynced; + }, + + onSignOutRequested: function() { + const { shouldShowSyncWarning } = this.state; + console.log(shouldShowSyncWarning); // eslint-disable-line no-console + // If user clicks on log out button a second time, sign out + if (shouldShowSyncWarning) { + this.setState({ shouldShowSyncWarning: false }); + //this.props.onSignOut(); + return; + } + + // Safety first! Check for unsynced notes. + if (this.hasUnsyncedNotes()) { + console.log('UNSYNCED!'); // eslint-disable-line no-console + this.setState({ shouldShowSyncWarning: true }); + } else { + //this.props.onSignOut(); + } + }, + render() { var dialog = this.props.dialog; @@ -75,6 +117,8 @@ export const SettingsDialog = React.createClass({ }, } = this.props; + const { shouldShowSyncWarning } = this.state; + switch (tabName) { case 'account': return ( @@ -91,11 +135,22 @@ export const SettingsDialog = React.createClass({ + {shouldShowSyncWarning && ( +
+

Unsynced Notes Detected

+

+ Logging out may delete notes that have not synced. Check + your connection and perhaps export your notes to ensure you + don't lose any content. Click 'Log Out' again + to proceed logging out. +

+
+ )}
  • - {shouldShowSyncWarning && ( -
    -

    Unsynced Notes Detected

    -

    - Logging out may delete notes that have not synced. Check - your connection and perhaps export your notes to ensure you - don't lose any content. Click 'Log Out' again - to proceed logging out. -

    -
    - )}