mirror of
https://github.com/haiwen/seahub.git
synced 2025-04-27 11:01: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);
|
||||
|
||||
const handleBeforeUnload = (event) => {
|
||||
if (isChangedRef.current) {
|
||||
event.preventDefault();
|
||||
event.returnValue = '';
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||
|
||||
return () => {
|
||||
clearInterval(saveInterval);
|
||||
window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||
};
|
||||
}, [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 isHotkey from 'is-hotkey';
|
||||
import CodeMirrorLoading from '../../components/code-mirror-loading';
|
||||
@ -13,6 +13,7 @@ const SimpleEditor = ({
|
||||
isFetching
|
||||
}) => {
|
||||
const [excalidrawAPI, setExcalidrawAPI] = useState(null);
|
||||
const prevElementsRef = useRef([]);
|
||||
const UIOptions = {
|
||||
canvasActions: {
|
||||
saveToActiveFile: false,
|
||||
@ -23,7 +24,10 @@ const SimpleEditor = ({
|
||||
|
||||
const handleChange = () => {
|
||||
const elements = excalidrawAPI.getSceneElements();
|
||||
onChangeContent(elements);
|
||||
if (hasChanged(elements, prevElementsRef.current)) {
|
||||
onChangeContent(elements);
|
||||
}
|
||||
prevElementsRef.current = elements;
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
@ -40,6 +44,14 @@ const SimpleEditor = ({
|
||||
};
|
||||
}, [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) {
|
||||
return (
|
||||
<div className='excali-container'>
|
||||
|
Loading…
Reference in New Issue
Block a user