mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 20:42:44 +00:00
Fis autosaveWarning
This commit is contained in:
@@ -35,7 +35,7 @@ import { updateHistory, versionHistoryGarbageCollection } from '../../utils/vers
|
|||||||
|
|
||||||
import googleDriveIcon from '../../googleDrive.svg';
|
import googleDriveIcon from '../../googleDrive.svg';
|
||||||
|
|
||||||
const SAVE_TIMEOUT = 5000;
|
const SAVE_TIMEOUT = 10000;
|
||||||
|
|
||||||
const EditPage = (props) => {
|
const EditPage = (props) => {
|
||||||
props = {
|
props = {
|
||||||
@@ -58,7 +58,7 @@ const EditPage = (props) => {
|
|||||||
const [confirmGoogleTransfer , setConfirmGoogleTransfer ] = useState(false);
|
const [confirmGoogleTransfer , setConfirmGoogleTransfer ] = useState(false);
|
||||||
const [url , setUrl ] = useState('');
|
const [url , setUrl ] = useState('');
|
||||||
const [autoSaveEnabled , setAutoSaveEnabled ] = useState(true);
|
const [autoSaveEnabled , setAutoSaveEnabled ] = useState(true);
|
||||||
const [autoSaveWarning , setAutoSaveWarning ] = useState(false);
|
const [autoSaveWarning , setAutoSaveWarning ] = useState(true);
|
||||||
const [unsavedTime , setUnsavedTime ] = useState(new Date());
|
const [unsavedTime , setUnsavedTime ] = useState(new Date());
|
||||||
|
|
||||||
const editorRef = useRef(null);
|
const editorRef = useRef(null);
|
||||||
@@ -297,6 +297,7 @@ const EditPage = (props) => {
|
|||||||
// #2 - Unsaved changes exist, autosave is OFF and warning timer has expired, show AUTOSAVE WARNING
|
// #2 - Unsaved changes exist, autosave is OFF and warning timer has expired, show AUTOSAVE WARNING
|
||||||
if (unsavedChanges && autoSaveWarning) {
|
if (unsavedChanges && autoSaveWarning) {
|
||||||
resetAutoSaveWarning();
|
resetAutoSaveWarning();
|
||||||
|
console.log("just set the timer")
|
||||||
const elapsedTime = Math.round((new Date() - unsavedTime) / 1000 / 60);
|
const elapsedTime = Math.round((new Date() - unsavedTime) / 1000 / 60);
|
||||||
const text = elapsedTime === 0
|
const text = elapsedTime === 0
|
||||||
? 'Autosave is OFF.'
|
? 'Autosave is OFF.'
|
||||||
@@ -323,13 +324,13 @@ const EditPage = (props) => {
|
|||||||
const toggleAutoSave = () => {
|
const toggleAutoSave = () => {
|
||||||
if (warningTimer.current) clearTimeout(warningTimer.current);
|
if (warningTimer.current) clearTimeout(warningTimer.current);
|
||||||
localStorage.setItem('AUTOSAVE_ON', JSON.stringify(!autoSaveEnabled));
|
localStorage.setItem('AUTOSAVE_ON', JSON.stringify(!autoSaveEnabled));
|
||||||
|
setAutoSaveWarning(autoSaveWarning);
|
||||||
setAutoSaveEnabled(!autoSaveEnabled);
|
setAutoSaveEnabled(!autoSaveEnabled);
|
||||||
setAutoSaveWarning(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const resetAutoSaveWarning = () => {
|
const resetAutoSaveWarning = () => {
|
||||||
setTimeout(setAutoSaveWarning(false), 4000); // Hide the warning after 4 seconds
|
setTimeout(()=>setAutoSaveWarning(false), 4000); // Hide the warning after 4 seconds
|
||||||
warningTimer.current = setTimeout(setAutoSaveWarning(true), 900000); // 15 minutes between unsaved changes warnings
|
warningTimer.current = setTimeout(()=>setAutoSaveWarning(true), 3000); // 15 minutes between unsaved changes warnings
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderAutoSaveButton = () => (
|
const renderAutoSaveButton = () => (
|
||||||
|
|||||||
Reference in New Issue
Block a user