0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-11 19:52:41 +00:00

add unsavedTime state for better notification

This commit is contained in:
Gazook89
2022-09-30 11:24:15 -05:00
parent 0cd598ae14
commit 8609026531

View File

@@ -64,7 +64,8 @@ const EditPage = createClass({
htmlErrors : Markdown.validate(this.props.brew.text), htmlErrors : Markdown.validate(this.props.brew.text),
url : '', url : '',
autoSave : true, autoSave : true,
autoSaveWarning : false autoSaveWarning : false,
unsavedTime : new Date()
}; };
}, },
savedBrew : null, savedBrew : null,
@@ -74,6 +75,7 @@ const EditPage = createClass({
url : window.location.href url : window.location.href
}); });
this.savedBrew = JSON.parse(JSON.stringify(this.props.brew)); //Deep copy this.savedBrew = JSON.parse(JSON.stringify(this.props.brew)); //Deep copy
this.setState({ autoSave: JSON.parse(localStorage.getItem('AUTOSAVE_ON')) }, ()=>{ this.setState({ autoSave: JSON.parse(localStorage.getItem('AUTOSAVE_ON')) }, ()=>{
@@ -230,8 +232,9 @@ const EditPage = createClass({
editId : this.savedBrew.editId, editId : this.savedBrew.editId,
shareId : this.savedBrew.shareId shareId : this.savedBrew.shareId
}, },
isPending : false, isPending : false,
isSaving : false, isSaving : false,
unsavedTime : new Date()
})); }));
}, },
@@ -339,13 +342,14 @@ const EditPage = createClass({
} }
if(this.state.autoSaveWarning){ if(this.state.autoSaveWarning){
console.log(this.state.unsavedTime);
setTimeout(()=>this.setState({ autoSaveWarning: false }), 4000); setTimeout(()=>this.setState({ autoSaveWarning: false }), 4000);
this.setAutosaveWarning(); this.setAutosaveWarning();
return <Nav.item className='save error' icon='fas fa-exclamation-circle'> return <Nav.item className='save error' icon='fas fa-exclamation-circle'>
Reminder... Reminder...
<div className='errorContainer'> <div className='errorContainer'>
Autosave has been turned off, and you haven't saved for {Math.round((new Date() - new Date(this.props.brew.updatedAt)) / 1000 / 60)} minutes. Autosave has been turned off, and you haven't saved for {Math.round((new Date() - this.state.unsavedTime) / 1000 / 60)} minutes.
</div> </div>
</Nav.item>; </Nav.item>;
} }