Confirm save on exit via back button

pull/1575/head
Rick Carlino 2019-11-15 15:55:22 -06:00
parent 8a903b7463
commit f86182f46a
1 changed files with 9 additions and 1 deletions

View File

@ -21,8 +21,15 @@ export class PlantGrid extends React.Component<PlantGridProps, PlantGridState> {
this.setState({ grid });
};
confirmUnsaved = () => {
const prompt = t("You have unsaved changes. Would you like to save them?");
const action = confirm(prompt) ?
saveGrid(this.state.gridId) : stashGrid(this.state.gridId);
this.props.dispatch(action);
}
componentWillUnmount() {
if (this.state.status === "dirty") { this.revertPreview(); }
(this.state.status === "dirty") && this.confirmUnsaved();
}
performPreview = () => {
@ -42,6 +49,7 @@ export class PlantGrid extends React.Component<PlantGridProps, PlantGridState> {
this.setState({ status: "dirty" });
}
revertPreview = () => {
const p: Promise<{}> = this.props.dispatch(stashGrid(this.state.gridId));
p.then(() => this.setState({ status: "clean" }));