fix a bug with clear segments

pull/1474/head
Mikael Finstad 4 years ago
parent a22dcdc92c
commit 5347dbdff0
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -638,7 +638,7 @@ const App = memo(() => {
setCanvasPlayerEventId(0); setCanvasPlayerEventId(0);
setDuration(); setDuration();
cutSegmentsHistory.go(0); cutSegmentsHistory.go(0);
clearSegments(); // TODO this will cause two history items clearSegments();
setCutStartTimeManual(); setCutStartTimeManual();
setCutEndTimeManual(); setCutEndTimeManual();
setFileFormat(); setFileFormat();

@ -142,16 +142,20 @@ export default ({
}, [currentApparentCutSeg.end, currentApparentCutSeg.start, filePath, loadCutSegments, mainVideoStream]); }, [currentApparentCutSeg.end, currentApparentCutSeg.start, filePath, loadCutSegments, mainVideoStream]);
const removeSegments = useCallback((removeSegmentIds) => { const removeSegments = useCallback((removeSegmentIds) => {
if (cutSegments.length === 1 && cutSegments[0].start == null && cutSegments[0].end == null) return; // We are at initial segment, nothing more we can do (it cannot be removed) setCutSegments((existingSegments) => {
setCutSegments((existing) => { if (existingSegments.length === 1 && existingSegments[0].start == null && existingSegments[0].end == null) {
const newSegments = existing.filter((seg) => !removeSegmentIds.includes(seg.segId)); return existingSegments; // We are at initial segment, nothing more we can do (it cannot be removed)
}
const newSegments = existingSegments.filter((seg) => !removeSegmentIds.includes(seg.segId));
if (newSegments.length === 0) { if (newSegments.length === 0) {
clearSegments(); // when removing the last segments, we start over // when removing the last segments, we start over
return existing; clearSegCounter();
return createInitialCutSegments();
} }
return newSegments; return newSegments;
}); });
}, [clearSegments, cutSegments, setCutSegments]); }, [clearSegCounter, createInitialCutSegments, setCutSegments]);
const removeCutSegment = useCallback((index) => { const removeCutSegment = useCallback((index) => {
removeSegments([cutSegments[index].segId]); removeSegments([cutSegments[index].segId]);

Loading…
Cancel
Save