mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-12 15:22:45 +00:00
lint
This commit is contained in:
@@ -66,7 +66,7 @@ const EditPage = (props)=>{
|
|||||||
const lastSavedBrew = useRef(_.cloneDeep(props.brew));
|
const lastSavedBrew = useRef(_.cloneDeep(props.brew));
|
||||||
const saveTimeout = useRef(null);
|
const saveTimeout = useRef(null);
|
||||||
const warnUnsavedTimeout = useRef(null);
|
const warnUnsavedTimeout = useRef(null);
|
||||||
const trySaveRef = useRef(trySave); // CTRL+S listener lives outside React and needs ref to use trySave with latest copy of brew
|
const trySaveRef = useRef(trySave); // CTRL+S listener lives outside React and needs ref to use trySave with latest copy of brew
|
||||||
const unsavedChangesRef = useRef(unsavedChanges); // Similarly, onBeforeUnload lives outside React and needs ref to unsavedChanges
|
const unsavedChangesRef = useRef(unsavedChanges); // Similarly, onBeforeUnload lives outside React and needs ref to unsavedChanges
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
@@ -76,11 +76,11 @@ const EditPage = (props)=>{
|
|||||||
setHTMLErrors(Markdown.validate(currentBrew.text));
|
setHTMLErrors(Markdown.validate(currentBrew.text));
|
||||||
fetchThemeBundle(setError, setThemeBundle, currentBrew.renderer, currentBrew.theme);
|
fetchThemeBundle(setError, setThemeBundle, currentBrew.renderer, currentBrew.theme);
|
||||||
|
|
||||||
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);
|
||||||
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();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ const EditPage = (props)=>{
|
|||||||
if(unsavedChangesRef.current)
|
if(unsavedChangesRef.current)
|
||||||
return 'You have unsaved changes!';
|
return 'You have unsaved changes!';
|
||||||
};
|
};
|
||||||
return () => {
|
return ()=>{
|
||||||
document.removeEventListener('keydown', handleControlKeys);
|
document.removeEventListener('keydown', handleControlKeys);
|
||||||
window.onBeforeUnload = null;
|
window.onBeforeUnload = null;
|
||||||
};
|
};
|
||||||
@@ -160,7 +160,7 @@ const EditPage = (props)=>{
|
|||||||
const resetWarnUnsavedTimer = ()=>{
|
const resetWarnUnsavedTimer = ()=>{
|
||||||
setTimeout(()=>setWarnUnsavedChanges(false), UNSAVED_WARNING_POPUP_TIMEOUT); // Hide the warning after 4 seconds
|
setTimeout(()=>setWarnUnsavedChanges(false), UNSAVED_WARNING_POPUP_TIMEOUT); // Hide the warning after 4 seconds
|
||||||
clearTimeout(warnUnsavedTimeout.current);
|
clearTimeout(warnUnsavedTimeout.current);
|
||||||
warnUnsavedTimeout.current = setTimeout(()=>setWarnUnsavedChanges(true), UNSAVED_WARNING_TIMEOUT); // 15 minutes between unsaved work warnings
|
warnUnsavedTimeout.current = setTimeout(()=>setWarnUnsavedChanges(true), UNSAVED_WARNING_TIMEOUT); // 15 minutes between unsaved work warnings
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleGoogleClick = ()=>{
|
const handleGoogleClick = ()=>{
|
||||||
@@ -192,7 +192,7 @@ const EditPage = (props)=>{
|
|||||||
if(!hasChanges && !immediate) return;
|
if(!hasChanges && !immediate) return;
|
||||||
const newTimeout = immediate ? 0 : SAVE_TIMEOUT;
|
const newTimeout = immediate ? 0 : SAVE_TIMEOUT;
|
||||||
|
|
||||||
saveTimeout.current = setTimeout(async () => {
|
saveTimeout.current = setTimeout(async ()=>{
|
||||||
setIsSaving(true);
|
setIsSaving(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
await save(currentBrew, saveGoogle)
|
await save(currentBrew, saveGoogle)
|
||||||
@@ -238,10 +238,10 @@ const EditPage = (props)=>{
|
|||||||
if(!res) return;
|
if(!res) return;
|
||||||
|
|
||||||
const updatedFields = {
|
const updatedFields = {
|
||||||
googleId: res.body.googleId ?? null,
|
googleId : res.body.googleId ?? null,
|
||||||
editId : res.body.editId,
|
editId : res.body.editId,
|
||||||
shareId : res.body.shareId,
|
shareId : res.body.shareId,
|
||||||
version : res.body.version
|
version : res.body.version
|
||||||
};
|
};
|
||||||
|
|
||||||
lastSavedBrew.current = {
|
lastSavedBrew.current = {
|
||||||
@@ -307,8 +307,8 @@ const EditPage = (props)=>{
|
|||||||
|
|
||||||
return <Nav.item className='save error' icon='fas fa-exclamation-circle'>
|
return <Nav.item className='save error' icon='fas fa-exclamation-circle'>
|
||||||
Reminder...
|
Reminder...
|
||||||
<div className='errorContainer'>{text}</div>
|
<div className='errorContainer'>{text}</div>
|
||||||
</Nav.item>
|
</Nav.item>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// #3 - Unsaved changes exist, click to save, show SAVE NOW
|
// #3 - Unsaved changes exist, click to save, show SAVE NOW
|
||||||
@@ -353,9 +353,9 @@ const EditPage = (props)=>{
|
|||||||
{error
|
{error
|
||||||
? <ErrorNavItem error={error} clearError={clearError} />
|
? <ErrorNavItem error={error} clearError={clearError} />
|
||||||
: <Nav.dropdown className='save-menu'>
|
: <Nav.dropdown className='save-menu'>
|
||||||
{renderSaveButton()}
|
{renderSaveButton()}
|
||||||
{renderAutoSaveButton()}
|
{renderAutoSaveButton()}
|
||||||
</Nav.dropdown>}
|
</Nav.dropdown>}
|
||||||
<NewBrewItem/>
|
<NewBrewItem/>
|
||||||
<HelpNavItem/>
|
<HelpNavItem/>
|
||||||
<ShareNavItem brew={currentBrew} />
|
<ShareNavItem brew={currentBrew} />
|
||||||
|
|||||||
Reference in New Issue
Block a user