11import { ArrowDown , Film , Plus , RotateCw , Search , X } from "lucide-react" ;
2- import { useMemo , useState } from "react" ;
2+ import { useMemo , useRef , useState } from "react" ;
33import { toast } from "sonner" ;
44import { Tooltip } from "@/components/ui/tooltip" ;
55import { useI18n , useScopedT } from "@/contexts/I18nContext" ;
@@ -9,7 +9,7 @@ import type {
99 AxcutTranscript ,
1010 TranscriptLanguageCode ,
1111} from "@/lib/ai-edition/schema" ;
12- import { useProjectStore , waitForDocumentSaves } from "@/lib/ai-edition/store/projectStore" ;
12+ import { useProjectStore } from "@/lib/ai-edition/store/projectStore" ;
1313import {
1414 useAssetTranscriptions ,
1515 useTranscriptionStore ,
@@ -87,6 +87,7 @@ export function MediaStage({
8787 const document = useProjectStore ( ( s ) => s . document ) ;
8888 const addAsset = useProjectStore ( ( s ) => s . addAsset ) ;
8989 const saveDocument = useProjectStore ( ( s ) => s . saveDocument ) ;
90+ const vocabularySave = useRef < Promise < boolean > > ( undefined ) ;
9091 // Transcripts are produced in the background as soon as a media lands here
9192 // (see transcriptionStore) — this stage only reports where each one is at,
9293 // and lets the user force a re-run in another language.
@@ -433,7 +434,7 @@ export function MediaStage({
433434 // document, so a stale one would undo a transcript written meanwhile.
434435 const latest = useProjectStore . getState ( ) . document ;
435436 const next = latest && withVocabulary ( latest , e . target . value ) ;
436- if ( next ) void saveDocument ( next , { history : true } ) ;
437+ if ( next ) vocabularySave . current = saveDocument ( next , { history : true } ) ;
437438 } }
438439 style = { {
439440 width : "100%" ,
@@ -498,8 +499,11 @@ export function MediaStage({
498499 ? undefined
499500 : async ( ) => {
500501 // Clicking here blurs the terms field, whose save is still in
501- // flight: the run must read the terms it just saved.
502- if ( ( await waitForDocumentSaves ( ) ) === "timeout" ) return ;
502+ // flight: the run must read the terms it just saved, so a failed
503+ // save (already toasted) runs nothing.
504+ const saving = vocabularySave . current ;
505+ vocabularySave . current = undefined ;
506+ if ( ( await saving ) === false ) return ;
503507 void requestTranscription ( selected . id , lang ) ;
504508 }
505509 }
0 commit comments