From 95497350e49260a2d607d970f8ba91a1b67a4c1c Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Wed, 28 Sep 2022 20:20:11 -0500 Subject: [PATCH] move test for autosave status to handleTextChange from trySave() --- client/homebrew/pages/editPage/editPage.jsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/client/homebrew/pages/editPage/editPage.jsx b/client/homebrew/pages/editPage/editPage.jsx index f3fad3f53..9a90d7ad9 100644 --- a/client/homebrew/pages/editPage/editPage.jsx +++ b/client/homebrew/pages/editPage/editPage.jsx @@ -25,6 +25,7 @@ const googleDriveActive = require('../../googleDrive.png'); const googleDriveInactive = require('../../googleDriveMono.png'); const SAVE_TIMEOUT = 3000; +const AUTOSAVE_TIMEOUT = 10000; const EditPage = createClass({ displayName : 'EditPage', @@ -120,14 +121,14 @@ const EditPage = createClass({ brew : { ...prevState.brew, text: text }, isPending : true, htmlErrors : htmlErrors - }), ()=>this.trySave()); + }), ()=>{if(this.state.autoSave) this.trySave();}); }, handleStyleChange : function(style){ this.setState((prevState)=>({ brew : { ...prevState.brew, style: style }, isPending : true - }), ()=>this.trySave()); + }), ()=>{if(this.state.autoSave) this.trySave();}); }, handleMetaChange : function(metadata){ @@ -137,7 +138,7 @@ const EditPage = createClass({ ...metadata }, isPending : true, - }), ()=>this.trySave()); + }), ()=>{if(this.state.autoSave) this.trySave();}); }, @@ -146,7 +147,13 @@ const EditPage = createClass({ }, trySave : function(){ - if(!this.state.autoSave){return;}; + // if(!this.state.autoSave){ + // if(this.autoSaveInterval){ + // clearInterval(this.autoSaveInterval); + // } + // this.autoSaveInterval = setInterval(this.trySave, 10000); + // return; + // }; if(!this.debounceSave) this.debounceSave = _.debounce(this.save, SAVE_TIMEOUT); if(this.hasChanges()){ this.debounceSave(); @@ -351,7 +358,7 @@ const EditPage = createClass({ this.setState((prevState)=>({ autoSave : !prevState.autoSave }), ()=>{ - this.trySave(); + if(this.state.autoSave) this.trySave(); localStorage.setItem('AUTOSAVE_ON', JSON.stringify(this.state.autoSave)); }); },