mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-09-25 00:42:57 +00:00
Move resetWarnUnsavedTimer and ToggleAutosave to common hook
This commit is contained in:
@@ -32,8 +32,6 @@ import Headtags from '@vitreum/headtags.js';
|
||||
const Meta = Headtags.Meta;
|
||||
|
||||
const SAVE_TIMEOUT = 10000;
|
||||
const UNSAVED_WARNING_TIMEOUT = 900000; //Warn user afer 15 minutes of unsaved changes
|
||||
const UNSAVED_WARNING_POPUP_TIMEOUT = 4000; //Show the warning for 4 seconds
|
||||
|
||||
const BREWKEY = 'HB_newPage_content';
|
||||
const STYLEKEY = 'HB_newPage_style';
|
||||
@@ -64,7 +62,6 @@ const HomePage =(props)=>{
|
||||
|
||||
const editorRef = useRef(null);
|
||||
const lastSavedBrew = useRef(_.cloneDeep(props.brew));
|
||||
const warnUnsavedTimeout = useRef(null);
|
||||
|
||||
const save = ()=>{
|
||||
request.post('/api')
|
||||
@@ -79,12 +76,6 @@ const HomePage =(props)=>{
|
||||
});
|
||||
};
|
||||
|
||||
const resetWarnUnsavedTimer = ()=>{
|
||||
setTimeout(()=>setWarnUnsavedChanges(false), UNSAVED_WARNING_POPUP_TIMEOUT); // Hide the warning after 4 seconds
|
||||
clearTimeout(warnUnsavedTimeout.current);
|
||||
warnUnsavedTimeout.current = setTimeout(()=>setWarnUnsavedChanges(true), UNSAVED_WARNING_TIMEOUT); // 15 minutes between unsaved work warnings
|
||||
};
|
||||
|
||||
const renderSaveButton = ()=>{
|
||||
// #1 - Currently saving, show SAVING
|
||||
if(isSaving)
|
||||
@@ -142,6 +133,7 @@ const HomePage =(props)=>{
|
||||
};
|
||||
|
||||
const {
|
||||
resetWarnUnsavedTimer,
|
||||
handleSplitMove,
|
||||
handleBrewChange
|
||||
} = useCommonEditPageFunctions({
|
||||
|
||||
Reference in New Issue
Block a user