diff --git a/client/homebrew/pages/editPage/editPage.jsx b/client/homebrew/pages/editPage/editPage.jsx
index 4db6d6e23..dc2520373 100644
--- a/client/homebrew/pages/editPage/editPage.jsx
+++ b/client/homebrew/pages/editPage/editPage.jsx
@@ -102,6 +102,14 @@ const EditPage = createClass({
window.onbeforeunload = function(){};
document.removeEventListener('keydown', this.handleControlKeys);
},
+ componentDidUpdate : function(){
+ const hasChange = this.hasChanges();
+ if(this.state.isPending != hasChange){
+ this.setState({
+ isPending : hasChange
+ });
+ }
+ },
handleControlKeys : function(e){
if(!(e.ctrlKey || e.metaKey)) return;
@@ -138,15 +146,13 @@ const EditPage = createClass({
this.setState((prevState)=>({
brew : { ...prevState.brew, text: text },
- isPending : true,
htmlErrors : htmlErrors,
}), ()=>{if(this.state.autoSave) this.trySave();});
},
handleStyleChange : function(style){
this.setState((prevState)=>({
- brew : { ...prevState.brew, style: style },
- isPending : true
+ brew : { ...prevState.brew, style: style }
}), ()=>{if(this.state.autoSave) this.trySave();});
},
@@ -158,8 +164,7 @@ const EditPage = createClass({
brew : {
...prevState.brew,
...metadata
- },
- isPending : true,
+ }
}), ()=>{if(this.state.autoSave) this.trySave();});
},
@@ -247,16 +252,17 @@ const EditPage = createClass({
});
if(!res) return;
- this.savedBrew = res.body;
+ this.savedBrew = {
+ ...this.state.brew,
+ googleId : res.body.googleId ? res.body.googleId : null,
+ editId : res.body.editId,
+ shareId : res.body.shareId,
+ version : res.body.version
+ };
history.replaceState(null, null, `/edit/${this.savedBrew.editId}`);
- this.setState((prevState)=>({
- brew : { ...prevState.brew,
- googleId : this.savedBrew.googleId ? this.savedBrew.googleId : null,
- editId : this.savedBrew.editId,
- shareId : this.savedBrew.shareId,
- version : this.savedBrew.version
- },
+ this.setState(()=>({
+ brew : this.savedBrew,
isPending : false,
isSaving : false,
unsavedTime : new Date()
@@ -311,7 +317,14 @@ const EditPage = createClass({
},
renderSaveButton : function(){
- if(this.state.autoSaveWarning && this.hasChanges()){
+
+ // #1 - Currently saving, show SAVING
+ if(this.state.isSaving){
+ return saving...;
+ }
+
+ // #2 - Unsaved changes exist, autosave is OFF and warning timer has expired, show AUTOSAVE WARNING
+ if(this.state.isPending && this.state.autoSaveWarning){
this.setAutosaveWarning();
const elapsedTime = Math.round((new Date() - this.state.unsavedTime) / 1000 / 60);
const text = elapsedTime == 0 ? 'Autosave is OFF.' : `Autosave is OFF, and you haven't saved for ${elapsedTime} minutes.`;
@@ -324,18 +337,17 @@ const EditPage = createClass({
;
}
- if(this.state.isSaving){
- return saving...;
+ // #3 - Unsaved changes exist, click to save, show SAVE NOW
+ // Use trySave(true) instead of save() to use debounced save function
+ if(this.state.isPending){
+ return this.trySave(true)} color='blue' icon='fas fa-save'>Save Now;
}
- if(this.state.isPending && this.hasChanges()){
- return Save Now;
- }
- if(!this.state.isPending && !this.state.isSaving && this.state.autoSave){
+ // #4 - No unsaved changes, autosave is ON, show AUTO-SAVED
+ if(this.state.autoSave){
return auto-saved.;
}
- if(!this.state.isPending && !this.state.isSaving){
- return saved.;
- }
+ // DEFAULT - No unsaved changes, show SAVED
+ return saved.;
},
handleAutoSave : function(){