debounce saving of project file

pull/276/head
Mikael Finstad 2020-02-23 22:55:49 +08:00
rodzic 3004cfee69
commit 6b2d3e5013
1 zmienionych plików z 17 dodań i 8 usunięć

Wyświetl plik

@ -130,11 +130,18 @@ const App = memo(() => {
createInitialCutSegments(), createInitialCutSegments(),
100, 100,
); );
const [debouncedCutSegments, setDebouncedCutSegments] = useState(
createInitialCutSegments(),
);
const [, cancelCommandedTimeDebounce] = useDebounce(() => { const [, cancelCommandedTimeDebounce] = useDebounce(() => {
setDebouncedCommandedTime(commandedTime); setDebouncedCommandedTime(commandedTime);
}, 300, [commandedTime]); }, 300, [commandedTime]);
const [, cancelCutSegmentsDebounce] = useDebounce(() => {
setDebouncedCutSegments(cutSegments);
}, 500, [cutSegments]);
// Preferences // Preferences
const [captureFormat, setCaptureFormat] = useState(configStore.get('captureFormat')); const [captureFormat, setCaptureFormat] = useState(configStore.get('captureFormat'));
@ -230,6 +237,8 @@ const App = memo(() => {
setPlaying(false); setPlaying(false);
setDuration(); setDuration();
cutSegmentsHistory.go(0); cutSegmentsHistory.go(0);
cancelCutSegmentsDebounce(); // TODO auto save when loading new file/closing file
setDebouncedCutSegments(createInitialCutSegments());
setCutSegments(createInitialCutSegments()); // TODO this will cause two history items setCutSegments(createInitialCutSegments()); // TODO this will cause two history items
setCutStartTimeManual(); setCutStartTimeManual();
setCutEndTimeManual(); setCutEndTimeManual();
@ -249,7 +258,7 @@ const App = memo(() => {
setZoom(1); setZoom(1);
setNeighbouringFrames([]); setNeighbouringFrames([]);
setShortestFlag(false); setShortestFlag(false);
}, [cutSegmentsHistory, setCutSegments, cancelCommandedTimeDebounce]); }, [cutSegmentsHistory, setCutSegments, cancelCommandedTimeDebounce, cancelCutSegmentsDebounce]);
useEffect(() => () => { useEffect(() => () => {
if (dummyVideoPath) unlink(dummyVideoPath).catch(console.error); if (dummyVideoPath) unlink(dummyVideoPath).catch(console.error);
@ -474,25 +483,25 @@ const App = memo(() => {
if (!autoSaveProjectFile) return; if (!autoSaveProjectFile) return;
// Initial state? don't save // Initial state? don't save
if (isEqual(cleanCutSegments(cutSegments), if (isEqual(cleanCutSegments(debouncedCutSegments),
cleanCutSegments(createInitialCutSegments()))) return; cleanCutSegments(createInitialCutSegments()))) return;
if (lastSavedCutSegmentsRef.current /* if (lastSavedCutSegmentsRef.current
&& isEqual(cleanCutSegments(lastSavedCutSegmentsRef.current), && isEqual(cleanCutSegments(lastSavedCutSegmentsRef.current),
cleanCutSegments(cutSegments))) { cleanCutSegments(debouncedCutSegments))) {
// console.log('Seg state didn\'t change, skipping save'); // console.log('Seg state didn\'t change, skipping save');
return; return;
} } */
await edlStore.save(edlFilePath, cutSegments); await edlStore.save(edlFilePath, debouncedCutSegments);
lastSavedCutSegmentsRef.current = cutSegments; lastSavedCutSegmentsRef.current = debouncedCutSegments;
} catch (err) { } catch (err) {
errorToast('Failed to save CSV'); errorToast('Failed to save CSV');
console.error('Failed to save CSV', err); console.error('Failed to save CSV', err);
} }
} }
save(); save();
}, [cutSegments, edlFilePath, autoSaveProjectFile]); }, [debouncedCutSegments, edlFilePath, autoSaveProjectFile]);
// 360 means we don't modify rotation // 360 means we don't modify rotation
const isRotationSet = rotation !== 360; const isRotationSet = rotation !== 360;