Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/components/ai-edition/NewEditorShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
useTimelineTranscriptGate,
useTranscriptionStore,
} from "@/lib/ai-edition/store/transcriptionStore";
import { enqueueTranscriptTextEdit } from "@/lib/ai-edition/store/transcriptTextEdit";
import { useUndoRedoShortcuts } from "@/lib/ai-edition/store/undo";
import { useSequentialTimelineOps } from "@/lib/ai-edition/store/useSequentialTimelineOps";
import { useTimeline } from "@/lib/ai-edition/store/useTimeline";
Expand Down Expand Up @@ -604,6 +605,32 @@ export function NewEditorShell() {
[applyTimelineOp],
);

// Capture the source project in the callback closure. Debounced saves and the pane's
// unmount flush can run after another project has loaded, so the queued task verifies
// this identity again before reading or persisting the current document.
const handleEditTranscriptText = useCallback(
async (assetId: string, wordIds: readonly string[], text: string): Promise<boolean> => {
if (!projectId) return false;
try {
return await enqueueTranscriptTextEdit({
sourceProjectId: projectId,
assetId,
wordIds,
text,
enqueue: enqueueTimelineWrite,
saveDocument,
});
} catch (error) {
console.error("[transcript] failed to edit text:", error);
toast.error("Could not edit transcript text", {
description: error instanceof Error ? error.message : String(error),
});
return false;
}
},
[enqueueTimelineWrite, projectId, saveDocument],
);

const handleSelectProject = useCallback(
async (id: string) => {
try {
Expand Down Expand Up @@ -1151,6 +1178,7 @@ export function NewEditorShell() {
onSeek: handleSeek,
onAddTrimRange: handleAddTrimRange,
onRemoveTrimRange: handleRemoveTrimRange,
onEditTranscriptText: handleEditTranscriptText,
onTranscribe: handleTranscribe,
canTranscribe: hasAsset,
isTranscribing: transcriptGate.state === "pending",
Expand Down
Loading