fix: await onDropMedia, fix stale closure deps, surface errors in TrackLane
- Import ActionResult type from @openreel/core - onDropMedia prop type now returns Promise<ActionResult> | void - handleDrop now awaits onDropMedia so failures are visible - Replace silent catch with console.error + toast.error on failure - Add allTracks, playheadPosition, snapSettings to handleDrop useCallback deps to fix stale closure bug (calculateSnap was using stale snap/track state)
This commit is contained in:
parent
76e6568ac6
commit
aec55fea83
1 changed files with 11 additions and 5 deletions
|
|
@ -5,6 +5,7 @@ import type {
|
|||
ShapeClip,
|
||||
SVGClip,
|
||||
StickerClip,
|
||||
ActionResult,
|
||||
} from "@openreel/core";
|
||||
import { ClipComponent } from "./ClipComponent";
|
||||
import { TextClipComponent } from "./TextClipComponent";
|
||||
|
|
@ -28,7 +29,7 @@ interface TrackLaneProps {
|
|||
trackHeights: Map<string, number>;
|
||||
timelineRef: React.RefObject<HTMLDivElement>;
|
||||
onSelectClip: (clipId: string, addToSelection: boolean) => void;
|
||||
onDropMedia: (trackId: string, mediaId: string, startTime: number) => void;
|
||||
onDropMedia: (trackId: string, mediaId: string, startTime: number) => Promise<ActionResult> | void;
|
||||
onMoveClip: (
|
||||
clipId: string,
|
||||
newStartTime: number,
|
||||
|
|
@ -178,13 +179,18 @@ export const TrackLane: React.FC<TrackLaneProps> = ({
|
|||
snapSettings,
|
||||
pixelsPerSecond,
|
||||
);
|
||||
onDropMedia(track.id, data.mediaId, snapResult.time);
|
||||
const result = await onDropMedia(track.id, data.mediaId, snapResult.time);
|
||||
if (result && !result.success) {
|
||||
console.error("[TrackLane] Failed to add clip:", result.error);
|
||||
toast.error("Failed to add clip", result.error?.message ?? "");
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Silently ignore parse errors
|
||||
} catch (err) {
|
||||
console.error("[TrackLane] Drop error:", err);
|
||||
toast.error("Failed to add clip", String(err));
|
||||
}
|
||||
},
|
||||
[track.id, track.name, pixelsPerSecond, scrollX, onDropMedia],
|
||||
[track.id, track.name, pixelsPerSecond, scrollX, onDropMedia, allTracks, playheadPosition, snapSettings],
|
||||
);
|
||||
|
||||
const handleResizeStart = useCallback(
|
||||
|
|
|
|||
Loading…
Reference in a new issue