mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-09-20 14:32:57 +00:00
Move handleSplitMove to common hook
This commit is contained in:
@@ -79,10 +79,6 @@ const EditPage = (props)=>{
|
||||
const saveTimeout = useRef(null);
|
||||
const warnUnsavedTimeout = useRef(null);
|
||||
|
||||
const handleSplitMove = ()=>{
|
||||
editorRef.current?.update();
|
||||
};
|
||||
|
||||
const updateBrew = (newData)=>setCurrentBrew((prevBrew)=>({
|
||||
...prevBrew,
|
||||
style : newData.style,
|
||||
@@ -321,6 +317,7 @@ const EditPage = (props)=>{
|
||||
};
|
||||
|
||||
const {
|
||||
handleSplitMove,
|
||||
handleBrewChange
|
||||
} = useCommonEditPageFunctions({
|
||||
saveGoogle,
|
||||
@@ -343,7 +340,8 @@ const EditPage = (props)=>{
|
||||
setUnsavedChanges,
|
||||
trySave,
|
||||
sandbox,
|
||||
lastSavedBrew
|
||||
lastSavedBrew,
|
||||
editorRef
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -79,10 +79,6 @@ const HomePage =(props)=>{
|
||||
});
|
||||
};
|
||||
|
||||
const handleSplitMove = ()=>{
|
||||
editorRef.current.update();
|
||||
};
|
||||
|
||||
const resetWarnUnsavedTimer = ()=>{
|
||||
setTimeout(()=>setWarnUnsavedChanges(false), UNSAVED_WARNING_POPUP_TIMEOUT); // Hide the warning after 4 seconds
|
||||
clearTimeout(warnUnsavedTimeout.current);
|
||||
@@ -146,6 +142,7 @@ const HomePage =(props)=>{
|
||||
};
|
||||
|
||||
const {
|
||||
handleSplitMove,
|
||||
handleBrewChange
|
||||
} = useCommonEditPageFunctions({
|
||||
setError,
|
||||
@@ -166,7 +163,8 @@ const HomePage =(props)=>{
|
||||
unsavedChanges,
|
||||
setUnsavedChanges,
|
||||
sandbox,
|
||||
lastSavedBrew
|
||||
lastSavedBrew,
|
||||
editorRef
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -100,10 +100,6 @@ const NewPage = (props)=>{
|
||||
window.history.replaceState({}, window.location.title, '/new/');
|
||||
};
|
||||
|
||||
const handleSplitMove = ()=>{
|
||||
editorRef.current.update();
|
||||
};
|
||||
|
||||
const resetWarnUnsavedTimer = ()=>{
|
||||
setTimeout(()=>setWarnUnsavedChanges(false), UNSAVED_WARNING_POPUP_TIMEOUT); // Hide the warning after 4 seconds
|
||||
clearTimeout(warnUnsavedTimeout.current);
|
||||
@@ -200,6 +196,7 @@ const NewPage = (props)=>{
|
||||
);
|
||||
|
||||
const {
|
||||
handleSplitMove,
|
||||
handleBrewChange
|
||||
} = useCommonEditPageFunctions({
|
||||
setError,
|
||||
@@ -221,7 +218,8 @@ const NewPage = (props)=>{
|
||||
setUnsavedChanges,
|
||||
trySave,
|
||||
sandbox,
|
||||
lastSavedBrew
|
||||
lastSavedBrew,
|
||||
editorRef
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -26,7 +26,8 @@ export default function useCommonEditPageFunctions(dependencies) {
|
||||
saveGoogle = false,
|
||||
unsavedChanges,
|
||||
setUnsavedChanges,
|
||||
lastSavedBrew
|
||||
lastSavedBrew,
|
||||
editorRef
|
||||
} = dependencies;
|
||||
|
||||
const unsavedChangesRef = useRef(unsavedChanges); // onBeforeUnload lives outside React and needs ref to unsavedChanges
|
||||
@@ -35,7 +36,6 @@ export default function useCommonEditPageFunctions(dependencies) {
|
||||
useEffect(()=>{
|
||||
const autoSavePref = !sandbox && JSON.parse(localStorage.getItem(AUTOSAVE_KEY) ?? true);
|
||||
setAutoSaveEnabled(autoSavePref);
|
||||
console.log(autoSavePref)
|
||||
setWarnUnsavedChanges(!autoSavePref);
|
||||
setHTMLErrors(hbfm.validate(currentBrew.text));
|
||||
fetchThemeBundle(setError, setThemeBundle, currentBrew.renderer, currentBrew.theme);
|
||||
@@ -70,6 +70,9 @@ export default function useCommonEditPageFunctions(dependencies) {
|
||||
if(autoSaveEnabled) trySave(false, hasChange, saveGoogle);
|
||||
}, [currentBrew]);
|
||||
|
||||
const handleSplitMove = ()=>{
|
||||
editorRef.current.update();
|
||||
};
|
||||
|
||||
const handleBrewChange = (field)=>(value, subfield)=>{ //'text', 'style', 'snippets', 'metadata'
|
||||
if(subfield == 'renderer' || subfield == 'theme')
|
||||
@@ -95,6 +98,7 @@ export default function useCommonEditPageFunctions(dependencies) {
|
||||
};
|
||||
|
||||
return {
|
||||
handleSplitMove,
|
||||
handleBrewChange
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user