Skip to content

Commit

Permalink
Warn users when before signing out with unsynced notes (#702)
Browse files Browse the repository at this point in the history
* sign out warning, still a WIP

* Adding a native dialog when on electron, otherwise a humble js `confirm()` dialog.

* Removing some now-unused css.

* Logging > Signing

* Another update to `logging` vs `signing`.

* Adding support to check Simperium's new `hasLocalChanges` to see if there's any local modifications to notes before signing out.

* Changed an if statement to a ternary.

* Removing if statement, not needed with the callback in Simperium

* Use Promise.all so that we iterate through all notes until a rejection occurs.

h/t @beaucollins
  • Loading branch information
roundhill authored Feb 7, 2018
1 parent 6542947 commit 5e78ca0
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 8 deletions.
8 changes: 7 additions & 1 deletion lib/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,13 @@ export const App = connect(mapStateToProps, mapDispatchToProps)(
throw new Error('Unknown dialog type.');
}

return <DialogComponent {...this.props} {...{ key, dialog, params }} />;
return (
<DialogComponent
isElectron={isElectron()}
{...this.props}
{...{ key, dialog, params }}
/>
);
},
})
);
Expand Down
69 changes: 68 additions & 1 deletion lib/dialogs/settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const SettingsDialog = React.createClass({
propTypes: {
actions: PropTypes.object.isRequired,
onSignOut: PropTypes.func.isRequired,
isElectron: PropTypes.bool.isRequired,
},

onDone() {
Expand All @@ -37,6 +38,72 @@ 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;

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.all(notes.map(noteHasSynced)).then(
() => onSignOut(), // All good, sign out now!
() => this.showUnsyncedWarning() // Show a warning to the user
);
});
},

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;

Expand Down Expand Up @@ -91,7 +158,7 @@ export const SettingsDialog = React.createClass({
<button
type="button"
className="button button-primary"
onClick={this.props.onSignOut}
onClick={this.onSignOutRequested}
>
Log Out
</button>
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
"build": "NODE_ENV=development npm run build:dll && npm run build:app",
"build:app": "webpack --config ./webpack.config.js",
"build:dll": "webpack --config ./webpack.config.dll.js",
"build:prod":
"NODE_ENV=production webpack -p --config ./webpack.config.dll.js && webpack -p --config ./webpack.config.js",
"build:prod": "NODE_ENV=production webpack -p --config ./webpack.config.dll.js && webpack -p --config ./webpack.config.js",
"format": "prettier --write {desktop,lib,sass}/{**/,*}.{js,json,jsx,sass}",
"lint": "eslint --ext .js --ext .jsx lib",
"start":
"NODE_ENV=hot npm run build && webpack-dev-server --config ./webpack.config.js --content-base dist --host 0.0.0.0 --port 4000 --hot --inline"
"start": "NODE_ENV=hot npm run build && webpack-dev-server --config ./webpack.config.js --content-base dist --host 0.0.0.0 --port 4000 --hot --inline"
},
"license": "ISC",
"engines": {
"node": "7.9.0",
"npm": "4.2.0"
},
"browserslist": ["Chrome >= 58"],
"browserslist": [
"Chrome >= 58"
],
"jest": {
"rootDir": "lib",
"testRegex": "(/test/.*\\.jsx?)|(test\\.jsx?)$"
Expand Down Expand Up @@ -99,7 +99,7 @@
"serve-favicon": "2.4.3",
"showdown": "1.7.2",
"showdown-xss-filter": "0.2.0",
"simperium": "0.2.9"
"simperium": "0.3.1"
},
"optionalDependencies": {
"appdmg": "0.4.5"
Expand Down

0 comments on commit 5e78ca0

Please sign in to comment.