kopia lustrzana https://github.com/mifi/lossless-cut
optimize
rodzic
42b991a179
commit
6cc9285d60
21
src/App.jsx
21
src/App.jsx
|
@ -15,7 +15,6 @@ import Mousetrap from 'mousetrap';
|
||||||
|
|
||||||
import fromPairs from 'lodash/fromPairs';
|
import fromPairs from 'lodash/fromPairs';
|
||||||
import clamp from 'lodash/clamp';
|
import clamp from 'lodash/clamp';
|
||||||
import cloneDeep from 'lodash/cloneDeep';
|
|
||||||
import sortBy from 'lodash/sortBy';
|
import sortBy from 'lodash/sortBy';
|
||||||
import flatMap from 'lodash/flatMap';
|
import flatMap from 'lodash/flatMap';
|
||||||
import isEqual from 'lodash/isEqual';
|
import isEqual from 'lodash/isEqual';
|
||||||
|
@ -412,6 +411,12 @@ const App = memo(() => {
|
||||||
return ret;
|
return ret;
|
||||||
}, [duration, haveInvalidSegs, sortedCutSegments]);
|
}, [duration, haveInvalidSegs, sortedCutSegments]);
|
||||||
|
|
||||||
|
const updateSegAtIndex = useCallback((index, newProps) => {
|
||||||
|
const cutSegmentsNew = [...cutSegments];
|
||||||
|
cutSegmentsNew.splice(index, 1, { ...cutSegments[index], ...newProps });
|
||||||
|
setCutSegments(cutSegmentsNew);
|
||||||
|
}, [setCutSegments, cutSegments]);
|
||||||
|
|
||||||
const setCutTime = useCallback((type, time) => {
|
const setCutTime = useCallback((type, time) => {
|
||||||
if (!isDurationValid(duration)) return;
|
if (!isDurationValid(duration)) return;
|
||||||
|
|
||||||
|
@ -422,18 +427,12 @@ const App = memo(() => {
|
||||||
if (type === 'end' && time <= getSegApparentStart(currentSeg)) {
|
if (type === 'end' && time <= getSegApparentStart(currentSeg)) {
|
||||||
throw new Error('Start time must precede end time');
|
throw new Error('Start time must precede end time');
|
||||||
}
|
}
|
||||||
const cloned = cloneDeep(cutSegments);
|
updateSegAtIndex(currentSegIndexSafe, { [type]: Math.min(Math.max(time, 0), duration) });
|
||||||
cloned[currentSegIndexSafe][type] = Math.min(Math.max(time, 0), duration);
|
}, [currentSegIndexSafe, getSegApparentEnd, currentCutSeg, duration, updateSegAtIndex]);
|
||||||
setCutSegments(cloned);
|
|
||||||
}, [
|
|
||||||
currentSegIndexSafe, getSegApparentEnd, cutSegments, currentCutSeg, setCutSegments, duration,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const setCurrentSegmentName = useCallback((name) => {
|
const setCurrentSegmentName = useCallback((name) => {
|
||||||
const cloned = cloneDeep(cutSegments);
|
updateSegAtIndex(currentSegIndexSafe, { name });
|
||||||
cloned[currentSegIndexSafe].name = name;
|
}, [currentSegIndexSafe, updateSegAtIndex]);
|
||||||
setCutSegments(cloned);
|
|
||||||
}, [currentSegIndexSafe, cutSegments, setCutSegments]);
|
|
||||||
|
|
||||||
const updateCurrentSegOrder = useCallback((newOrder) => {
|
const updateCurrentSegOrder = useCallback((newOrder) => {
|
||||||
if (newOrder > cutSegments.length - 1 || newOrder < 0) return;
|
if (newOrder > cutSegments.length - 1 || newOrder < 0) return;
|
||||||
|
|
Ładowanie…
Reference in New Issue