mirror of
https://github.com/haiwen/seahub.git
synced 2025-07-15 07:52:14 +00:00
time-base saving & toastTips (#7662)
* time-base saving & toastTips * refactor hasChanged --------- Co-authored-by: First <first@FirstdeMacBook-Pro.local>
This commit is contained in:
parent
055bd575b9
commit
3ec456fff5
@ -59,8 +59,18 @@ const ExcaliEditor = () => {
|
|||||||
}
|
}
|
||||||
}, SAVE_INTERVAL_TIME);
|
}, SAVE_INTERVAL_TIME);
|
||||||
|
|
||||||
|
const handleBeforeUnload = (event) => {
|
||||||
|
if (isChangedRef.current) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.returnValue = '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
clearInterval(saveInterval);
|
clearInterval(saveInterval);
|
||||||
|
window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||||
};
|
};
|
||||||
}, [saveSceneContent]);
|
}, [saveSceneContent]);
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { Excalidraw, MainMenu } from '@excalidraw/excalidraw';
|
import { Excalidraw, MainMenu } from '@excalidraw/excalidraw';
|
||||||
import isHotkey from 'is-hotkey';
|
import isHotkey from 'is-hotkey';
|
||||||
import CodeMirrorLoading from '../../components/code-mirror-loading';
|
import CodeMirrorLoading from '../../components/code-mirror-loading';
|
||||||
@ -13,6 +13,7 @@ const SimpleEditor = ({
|
|||||||
isFetching
|
isFetching
|
||||||
}) => {
|
}) => {
|
||||||
const [excalidrawAPI, setExcalidrawAPI] = useState(null);
|
const [excalidrawAPI, setExcalidrawAPI] = useState(null);
|
||||||
|
const prevElementsRef = useRef([]);
|
||||||
const UIOptions = {
|
const UIOptions = {
|
||||||
canvasActions: {
|
canvasActions: {
|
||||||
saveToActiveFile: false,
|
saveToActiveFile: false,
|
||||||
@ -23,7 +24,10 @@ const SimpleEditor = ({
|
|||||||
|
|
||||||
const handleChange = () => {
|
const handleChange = () => {
|
||||||
const elements = excalidrawAPI.getSceneElements();
|
const elements = excalidrawAPI.getSceneElements();
|
||||||
|
if (hasChanged(elements, prevElementsRef.current)) {
|
||||||
onChangeContent(elements);
|
onChangeContent(elements);
|
||||||
|
}
|
||||||
|
prevElementsRef.current = elements;
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -40,6 +44,14 @@ const SimpleEditor = ({
|
|||||||
};
|
};
|
||||||
}, [excalidrawAPI, onSaveContent]);
|
}, [excalidrawAPI, onSaveContent]);
|
||||||
|
|
||||||
|
const hasChanged = (prev, current) => {
|
||||||
|
if (prev.length !== current.length) return true;
|
||||||
|
|
||||||
|
return current.some((element, index) => {
|
||||||
|
return element.version !== prev[index]?.version;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
if (isFetching) {
|
if (isFetching) {
|
||||||
return (
|
return (
|
||||||
<div className='excali-container'>
|
<div className='excali-container'>
|
||||||
|
Loading…
Reference in New Issue
Block a user