mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-09-25 02:52:57 +00:00
Convert trySaveRef to useEffectEvent
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import './homePage.less';
|
||||
|
||||
// Common imports
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import React, { useState, useEffect, useRef, useEffectEvent } from 'react';
|
||||
import request from '../../utils/request-middleware.js';
|
||||
import { hbfm } from 'hbmarkedwrapper';
|
||||
import _ from 'lodash';
|
||||
@@ -65,34 +65,8 @@ const HomePage =(props)=>{
|
||||
const editorRef = useRef(null);
|
||||
const lastSavedBrew = useRef(_.cloneDeep(props.brew));
|
||||
const warnUnsavedTimeout = useRef(null);
|
||||
const trySaveRef = useRef(null); // CTRL+S listener lives outside React and needs ref to use trySave with latest copy of brew
|
||||
const unsavedChangesRef = useRef(unsavedChanges);
|
||||
|
||||
const {
|
||||
handleBrewChange
|
||||
} = useCommonEditPageFunctions({
|
||||
setError,
|
||||
setThemeBundle,
|
||||
HTMLErrors,
|
||||
setHTMLErrors,
|
||||
currentBrew,
|
||||
setCurrentBrew,
|
||||
useLocalStorage,
|
||||
BREWKEY,
|
||||
STYLEKEY,
|
||||
SNIPKEY,
|
||||
METAKEY,
|
||||
hbfm,
|
||||
autoSaveEnabled,
|
||||
setAutoSaveEnabled,
|
||||
setWarnUnsavedChanges,
|
||||
trySaveRef,
|
||||
unsavedChangesRef,
|
||||
setUnsavedChanges,
|
||||
sandbox,
|
||||
lastSavedBrew
|
||||
});
|
||||
|
||||
useEffect(()=>{
|
||||
unsavedChangesRef.current = unsavedChanges;
|
||||
}, [unsavedChanges]);
|
||||
@@ -176,6 +150,30 @@ const HomePage =(props)=>{
|
||||
</Navbar>;
|
||||
};
|
||||
|
||||
const {
|
||||
handleBrewChange
|
||||
} = useCommonEditPageFunctions({
|
||||
setError,
|
||||
setThemeBundle,
|
||||
HTMLErrors,
|
||||
setHTMLErrors,
|
||||
currentBrew,
|
||||
setCurrentBrew,
|
||||
useLocalStorage,
|
||||
BREWKEY,
|
||||
STYLEKEY,
|
||||
SNIPKEY,
|
||||
METAKEY,
|
||||
hbfm,
|
||||
autoSaveEnabled,
|
||||
setAutoSaveEnabled,
|
||||
setWarnUnsavedChanges,
|
||||
unsavedChangesRef,
|
||||
setUnsavedChanges,
|
||||
sandbox,
|
||||
lastSavedBrew
|
||||
});
|
||||
|
||||
return (
|
||||
<div className='homePage sitePage'>
|
||||
<Meta name='google-site-verification' content='NwnAQSSJZzAT7N-p5MY6ydQ7Njm67dtbu73ZSyE5Fy4' />
|
||||
|
||||
Reference in New Issue
Block a user