Skip to content

The VS Code of video editing, built for agents.

TypeScript

feat: refactor auto-captions command and improve scene selection logic

konstantin-paulus66bed78f88a7
diff --git a/apps/web/src/components/commands/auto-captions.tsx b/apps/web/src/components/commands/auto-captions.tsx
index 364f2969..811ca847 100644
--- a/apps/web/src/components/commands/auto-captions.tsx
+++ b/apps/web/src/components/commands/auto-captions.tsx
@@ -2,14 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-import { Separator } from "@/components/ui/separator";
-import { useCommand, useCommands } from "@/context/commands";
+import { useCommand } from "@/context/commands";
import { useAutoCaptions } from "@/components/genai/use-auto-captions";
-import { useSelection } from "@/engine/hooks";
-import { ActionBar, ActionBarCancel, ActionBarConfirm, ActionBarTarget } from "@/components/canvas/action-bar";
export function AutoCaptionsCommand() {
- const { nodes } = useSelection();
const { scene, generate } = useAutoCaptions();
useCommand({
@@ -18,30 +14,9 @@ export function AutoCaptionsCommand() {
group: "Media",
icon: "captions",
keywords: ["auto-captions", "subtitles", "transcribe"],
- ready: () => !!scene() && nodes().includes(scene()!),
+ available: () => !!scene(),
run: generate,
- bar: AutoCaptionsBar,
});
return null;
}
-
-/** The active scene, captioned from its audio on Confirm. */
-function AutoCaptionsBar() {
- const { close } = useCommands();
- const { scene, generate } = useAutoCaptions();
-
- const confirm = () => {
- generate();
- close();
- };
-
- return (
- <ActionBar>
- <ActionBarTarget nodes={scene() ? [scene()!] : []} verb="Target:" empty="Open a scene to caption" />
- <Separator orientation="vertical" class="min-h-5" />
- <ActionBarCancel onCancel={close} />
- <ActionBarConfirm disabled={!scene()} onConfirm={confirm} hint="Caption" />
- </ActionBar>
- );
-}
diff --git a/apps/web/src/components/genai/use-auto-captions.tsx b/apps/web/src/components/genai/use-auto-captions.tsx
index 85e2cfb2..aaf3424b 100644
--- a/apps/web/src/components/genai/use-auto-captions.tsx
+++ b/apps/web/src/components/genai/use-auto-captions.tsx
@@ -3,20 +3,24 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { useWorld } from "@diffusionstudio/koota-solid";
+import { Scene } from "@diffusionstudio/runtime";
import { useProject } from "@/context/project";
import { generateCaptions } from "@/engine/generate";
-import { useActiveScene } from "@/engine/hooks";
+import { useActiveScene, useSelection } from "@/engine/hooks";
-/** Captions for the active scene, the one being edited: selecting a scene makes it active. */
+/** Captions for the selected scene, or the active one, the one being edited, when none is selected. */
export function useAutoCaptions() {
const world = useWorld();
const project = useProject();
- const scene = useActiveScene();
+ const { nodes } = useSelection();
+ const active = useActiveScene();
+
+ const scene = () => nodes().find((node) => node.has(Scene)) ?? active();
const generate = () => {
- const active = scene();
- if (active) {
- generateCaptions(world, active, project.dir());
+ const target = scene();
+ if (target) {
+ generateCaptions(world, target, project.dir());
}
};