Skip to content

Commit 0de6f16

Browse files
committed
Warn before discarding changes
1 parent 0be0e02 commit 0de6f16

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/frontend/components/App/index.jsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@ class App extends React.Component {
5050
CategoryApi.getCategories()
5151
.then(({ categories }) => this.props.setCategories(categories))
5252
.catch(this.props.showErrorToast);
53+
54+
window.onbeforeunload = () => this.isGistSaved() ? undefined : 'Changes you made will not be saved.';
5355
}
5456

5557
componentWillUnmount() {
5658
delete window.signIn;
5759
delete window.signOut;
60+
61+
window.onbeforeunload = undefined;
5862
}
5963

6064
componentWillReceiveProps(nextProps) {
@@ -119,8 +123,9 @@ class App extends React.Component {
119123
.catch(this.props.showErrorToast);
120124
}
121125

122-
// TODO: warn before loading or quiting if not saved
123126
loadAlgorithm({ categoryKey, algorithmKey, gistId }) {
127+
if (!this.isGistSaved() && !window.confirm('Are you sure want to discard changes?')) return;
128+
124129
const { ext } = this.props.env;
125130
let fetchPromise = null;
126131
if (categoryKey && algorithmKey) {

0 commit comments

Comments
 (0)