mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-05-07 18:48:39 +00:00
Merge pull request #4772 from 5e-Cleric/fix-save-on-load
fix save on load
This commit is contained in:
@@ -38,8 +38,6 @@ const themes = { default: defaultCM5Theme, ...cm5Themes, darkbrewery };
|
|||||||
const themeCompartment = new Compartment();
|
const themeCompartment = new Compartment();
|
||||||
const highlightCompartment = new Compartment();
|
const highlightCompartment = new Compartment();
|
||||||
|
|
||||||
console.log(themes);
|
|
||||||
|
|
||||||
import { generalKeymap, markdownKeymap } from './customKeyMaps.js';
|
import { generalKeymap, markdownKeymap } from './customKeyMaps.js';
|
||||||
import foldOnPages from './customFolding.js';
|
import foldOnPages from './customFolding.js';
|
||||||
import { customHighlightStyle, tokenizeCustomMarkdown, tokenizeCustomCSS } from './customHighlight.js';
|
import { customHighlightStyle, tokenizeCustomMarkdown, tokenizeCustomCSS } from './customHighlight.js';
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ const EditPage = (props)=>{
|
|||||||
|
|
||||||
const handleControlKeys = (e)=>{
|
const handleControlKeys = (e)=>{
|
||||||
if(!(e.ctrlKey || e.metaKey)) return;
|
if(!(e.ctrlKey || e.metaKey)) return;
|
||||||
if(e.keyCode === 83) trySaveRef.current(true);
|
if(e.keyCode === 83) trySaveRef.current(true, true, saveGoogle);
|
||||||
if(e.keyCode === 80) printCurrentBrew();
|
if(e.keyCode === 80) printCurrentBrew();
|
||||||
if([83, 80].includes(e.keyCode)) {
|
if([83, 80].includes(e.keyCode)) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@@ -118,13 +118,9 @@ const EditPage = (props)=>{
|
|||||||
const hasChange = !_.isEqual(currentBrew, lastSavedBrew.current);
|
const hasChange = !_.isEqual(currentBrew, lastSavedBrew.current);
|
||||||
setUnsavedChanges(hasChange);
|
setUnsavedChanges(hasChange);
|
||||||
|
|
||||||
if(autoSaveEnabled) trySave(false, hasChange);
|
if(autoSaveEnabled) trySave(false, hasChange, saveGoogle);
|
||||||
}, [currentBrew]);
|
}, [currentBrew]);
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
trySave(true);
|
|
||||||
}, [saveGoogle]);
|
|
||||||
|
|
||||||
const handleSplitMove = ()=>{
|
const handleSplitMove = ()=>{
|
||||||
editorRef.current?.update();
|
editorRef.current?.update();
|
||||||
};
|
};
|
||||||
@@ -183,11 +179,13 @@ const EditPage = (props)=>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
const toggleGoogleStorage = ()=>{
|
const toggleGoogleStorage = ()=>{
|
||||||
|
const newSaveGoogle = !saveGoogle;
|
||||||
setSaveGoogle((prev)=>!prev);
|
setSaveGoogle((prev)=>!prev);
|
||||||
setError(null);
|
setError(null);
|
||||||
|
trySave(true, true, newSaveGoogle);
|
||||||
};
|
};
|
||||||
|
|
||||||
const trySave = (immediate = false, hasChanges = true)=>{
|
const trySave = (immediate = false, hasChanges = true, saveToGoogle = false)=>{
|
||||||
clearTimeout(saveTimeout.current);
|
clearTimeout(saveTimeout.current);
|
||||||
if(isSaving) return;
|
if(isSaving) return;
|
||||||
if(!hasChanges && !immediate) return;
|
if(!hasChanges && !immediate) return;
|
||||||
@@ -196,7 +194,7 @@ const EditPage = (props)=>{
|
|||||||
saveTimeout.current = setTimeout(async ()=>{
|
saveTimeout.current = setTimeout(async ()=>{
|
||||||
setIsSaving(true);
|
setIsSaving(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
await save(currentBrew, saveGoogle)
|
await save(currentBrew, saveToGoogle)
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
setError(err);
|
setError(err);
|
||||||
});
|
});
|
||||||
@@ -314,7 +312,7 @@ const EditPage = (props)=>{
|
|||||||
|
|
||||||
// #3 - Unsaved changes exist, click to save, show SAVE NOW
|
// #3 - Unsaved changes exist, click to save, show SAVE NOW
|
||||||
if(unsavedChanges)
|
if(unsavedChanges)
|
||||||
return <Nav.item className='save' onClick={()=>trySave(true)} color='blue' icon='fas fa-save'>save now</Nav.item>;
|
return <Nav.item className='save' onClick={()=>trySave(true, true, saveGoogle)} color='blue' icon='fas fa-save'>save now</Nav.item>;
|
||||||
|
|
||||||
// #4 - No unsaved changes, autosave is ON, show AUTO-SAVED
|
// #4 - No unsaved changes, autosave is ON, show AUTO-SAVED
|
||||||
if(autoSaveEnabled)
|
if(autoSaveEnabled)
|
||||||
|
|||||||
Reference in New Issue
Block a user