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

Lines changed: 6 additions & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy