fix editor: use assetsRef to avoid stale closure in handleExternalDrop
This commit is contained in:
parent
87f14b7c71
commit
b345f5f6a4
1 changed files with 6 additions and 4 deletions
|
|
@ -40,6 +40,7 @@ function Editor() {
|
||||||
const historyIdxRef = React.useRef(0);
|
const historyIdxRef = React.useRef(0);
|
||||||
const currentSeqRef = React.useRef(null);
|
const currentSeqRef = React.useRef(null);
|
||||||
const isDirtyRef = React.useRef(false);
|
const isDirtyRef = React.useRef(false);
|
||||||
|
const assetsRef = React.useRef([]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const data = window.ZAMPP_DATA;
|
const data = window.ZAMPP_DATA;
|
||||||
|
|
@ -52,6 +53,7 @@ function Editor() {
|
||||||
|
|
||||||
React.useEffect(() => { currentSeqRef.current = currentSeq; }, [currentSeq]);
|
React.useEffect(() => { currentSeqRef.current = currentSeq; }, [currentSeq]);
|
||||||
React.useEffect(() => { isDirtyRef.current = isDirty; }, [isDirty]);
|
React.useEffect(() => { isDirtyRef.current = isDirty; }, [isDirty]);
|
||||||
|
React.useEffect(() => { assetsRef.current = assets; }, [assets]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const refreshAssets = function() {
|
const refreshAssets = function() {
|
||||||
|
|
@ -202,7 +204,7 @@ function Editor() {
|
||||||
const parsed = JSON.parse(raw);
|
const parsed = JSON.parse(raw);
|
||||||
assetId = parsed.assetId || parsed.id || assetId;
|
assetId = parsed.assetId || parsed.id || assetId;
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
const asset = assets.find(function(a) { return a.id === assetId; });
|
const asset = assetsRef.current.find(function(a) { return a.id === assetId; });
|
||||||
if (!asset) return;
|
if (!asset) return;
|
||||||
let streamUrl = streamCacheRef.current[asset.id];
|
let streamUrl = streamCacheRef.current[asset.id];
|
||||||
if (!streamUrl) {
|
if (!streamUrl) {
|
||||||
|
|
@ -573,7 +575,7 @@ function ClipContextMenu({ clip, x, y, onClose, onOpenSource, onDuplicate, onSpl
|
||||||
function ProgramMonitor({ videoRef, currentSeq, playheadFrames, setPlayheadFrames, streamCacheRef }) {
|
function ProgramMonitor({ videoRef, currentSeq, playheadFrames, setPlayheadFrames, streamCacheRef }) {
|
||||||
const [pgmPlaying, setPgmPlaying] = React.useState(false);
|
const [pgmPlaying, setPgmPlaying] = React.useState(false);
|
||||||
const [pgmClipIdx, setPgmClipIdx] = React.useState(-1);
|
const [pgmClipIdx, setPgmClipIdx] = React.useState(-1);
|
||||||
const [pgmClips, setPgmClips] = React.useState([]);
|
const [pgmClips, setPgMclips] = React.useState([]);
|
||||||
|
|
||||||
function getV1Clips() {
|
function getV1Clips() {
|
||||||
if (!currentSeq || !currentSeq.clips) return [];
|
if (!currentSeq || !currentSeq.clips) return [];
|
||||||
|
|
@ -587,7 +589,7 @@ function ProgramMonitor({ videoRef, currentSeq, playheadFrames, setPlayheadFrame
|
||||||
}
|
}
|
||||||
const v1 = getV1Clips();
|
const v1 = getV1Clips();
|
||||||
if (!v1.length) return;
|
if (!v1.length) return;
|
||||||
setPgmClips(v1);
|
setPgMclips(v1);
|
||||||
const idx = v1.findIndex(c => playheadFrames >= c.timeline_in_frames && playheadFrames < c.timeline_out_frames);
|
const idx = v1.findIndex(c => playheadFrames >= c.timeline_in_frames && playheadFrames < c.timeline_out_frames);
|
||||||
setPgmClipIdx(idx >= 0 ? idx : 0);
|
setPgmClipIdx(idx >= 0 ? idx : 0);
|
||||||
setPgmPlaying(true);
|
setPgmPlaying(true);
|
||||||
|
|
@ -681,4 +683,4 @@ function EditorKeyboard({ onUndo, onRedo, onSave, onMarkIn, onMarkOut, currentSe
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.Editor = Editor;
|
window.Editor = Editor;
|
||||||
Loading…
Reference in a new issue