-
Notifications
You must be signed in to change notification settings - Fork 563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn users when before signing out with unsynced notes #702
Changes from 8 commits
7a9e28c
721ae54
8abc96d
7492903
12fddee
3192698
9710609
f68b6eb
d56399e
5324686
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ export const SettingsDialog = React.createClass({ | |
propTypes: { | ||
actions: PropTypes.object.isRequired, | ||
onSignOut: PropTypes.func.isRequired, | ||
isElectron: PropTypes.bool.isRequired, | ||
}, | ||
|
||
onDone() { | ||
|
@@ -37,6 +38,74 @@ export const SettingsDialog = React.createClass({ | |
}); | ||
}, | ||
|
||
onSignOutRequested() { | ||
// Safety first! Check for any unsynced notes before signing out. | ||
const { onSignOut, noteBucket } = this.props; | ||
const { notes } = this.props.appState; | ||
const { getVersion } = noteBucket; | ||
|
||
if ( | ||
noteBucket.hasLocalChanges((error, hasChanges) => { | ||
if (hasChanges) { | ||
this.showUnsyncedWarning(); | ||
return; | ||
} | ||
|
||
// Also check persisted store for any notes with version 0 | ||
const noteHasSynced = note => | ||
new Promise((resolve, reject) => | ||
getVersion(note.id, (e, v) => (e || v === 0 ? reject() : resolve())) | ||
); | ||
|
||
Promise.race(notes.map(noteHasSynced)).then( | ||
() => onSignOut(), // All good, sign out now! | ||
() => this.showUnsyncedWarning() // Show a warning to the user | ||
); | ||
}) | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's going on here? is there a missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops, I had an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😄 looks better now |
||
}, | ||
|
||
showUnsyncedWarning() { | ||
const { isElectron } = this.props; | ||
isElectron ? this.showElectronWarningDialog() : this.showWebWarningDialog(); | ||
}, | ||
|
||
showElectronWarningDialog() { | ||
const { onSignOut } = this.props; | ||
const dialog = __non_webpack_require__('electron').remote.dialog; // eslint-disable-line no-undef | ||
dialog.showMessageBox( | ||
{ | ||
type: 'warning', | ||
buttons: ['Delete Notes', 'Cancel', 'Visit Web App'], | ||
title: 'Unsynced Notes Detected', | ||
message: | ||
'Logging out will delete any unsynced notes. You can verify your ' + | ||
'synced notes by logging in to the Web App.', | ||
}, | ||
response => { | ||
if (response === 0) { | ||
onSignOut(); | ||
} else if (response === 2) { | ||
viewExternalUrl('https://app.simplenote.com'); | ||
} | ||
} | ||
); | ||
}, | ||
|
||
showWebWarningDialog() { | ||
const { onSignOut } = this.props; | ||
const shouldReallySignOut = confirm( | ||
'Warning: Unsynced notes were detected.\n\n' + | ||
'Logging out will delete any notes that have not synced. ' + | ||
'Check your connection and visit app.simplenote.com to verify synced notes.' + | ||
'\n\nClick OK to delete unsynced notes and Log Out.' | ||
); | ||
|
||
if (shouldReallySignOut) { | ||
onSignOut(); | ||
} | ||
}, | ||
|
||
render() { | ||
var dialog = this.props.dialog; | ||
|
||
|
@@ -91,7 +160,7 @@ export const SettingsDialog = React.createClass({ | |
<button | ||
type="button" | ||
className="button button-primary" | ||
onClick={this.props.onSignOut} | ||
onClick={this.onSignOutRequested} | ||
> | ||
Log Out | ||
</button> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
Promise.all
notPromise.race
? You want to make sure that none of the notes are unsynced right?