Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Keep tab bars on screen while a tab's page loads

Adarsh0501f924ac37
diff --git a/src/app/(studio)/ads/loading.tsx b/src/app/(studio)/ads/loading.tsx
new file mode 100644
index 00000000..5fe78ed5
--- /dev/null
+++ b/src/app/(studio)/ads/loading.tsx
@@ -0,0 +1,6 @@
+import { MarketingToolSkeleton } from "@/components/marketing/skeletons";
+
+// Ads Studio and a brand's workspace: the marketing suite's header and tabs stay on screen while the page loads.
+export default function Loading() {
+ return <MarketingToolSkeleton title="Ads Studio" active="ads" />;
+}
diff --git a/src/app/(studio)/ads/multiplier/loading.tsx b/src/app/(studio)/ads/multiplier/loading.tsx
new file mode 100644
index 00000000..536bed5a
--- /dev/null
+++ b/src/app/(studio)/ads/multiplier/loading.tsx
@@ -0,0 +1,6 @@
+import { MarketingToolSkeleton } from "@/components/marketing/skeletons";
+
+// Its own fallback, so the Ads Studio skeleton (../loading.tsx) never stands in for this page.
+export default function Loading() {
+ return <MarketingToolSkeleton title="Ad Multiplier" active="multiplier" />;
+}
diff --git a/src/app/(studio)/audio/layout.tsx b/src/app/(studio)/audio/layout.tsx
new file mode 100644
index 00000000..fb7e5ceb
--- /dev/null
+++ b/src/app/(studio)/audio/layout.tsx
@@ -0,0 +1,6 @@
+import { HubFrame } from "@/components/studio/hub-chrome";
+
+/** The hub's title bar and mode tabs: shared by /audio and /audio/<mode>, so a tab switch keeps them on screen. */
+export default function Layout({ children }: { children: React.ReactNode }) {
+ return <HubFrame kind="audio">{children}</HubFrame>;
+}
diff --git a/src/app/(studio)/loading.tsx b/src/app/(studio)/loading.tsx
index ed76b86b..ba2bdbd3 100644
--- a/src/app/(studio)/loading.tsx
+++ b/src/app/(studio)/loading.tsx
@@ -1,5 +1,6 @@
-import { StudioSkeleton } from "@/components/skeletons";
+import { HubBodySkeleton, StudioSkeleton } from "@/components/skeletons";
+import { StudioRouteSkeleton } from "@/components/studio/hub-chrome";
export default function Loading() {
- return <StudioSkeleton />;
+ return <StudioRouteSkeleton generic={<StudioSkeleton />} hubBody={<HubBodySkeleton />} />;
}
diff --git a/src/app/(studio)/marketing/click-to-ad/loading.tsx b/src/app/(studio)/marketing/click-to-ad/loading.tsx
index dedb8379..5dbb0c92 100644
--- a/src/app/(studio)/marketing/click-to-ad/loading.tsx
+++ b/src/app/(studio)/marketing/click-to-ad/loading.tsx
@@ -1,6 +1,6 @@
-import { StudioSkeleton } from "@/components/skeletons";
+import { MarketingToolSkeleton } from "@/components/marketing/skeletons";
// Its own fallback, so the Marketing gallery's skeleton (../loading.tsx) never stands in for this form.
export default function Loading() {
- return <StudioSkeleton />;
+ return <MarketingToolSkeleton title="Click to Ad" active="click" />;
}
diff --git a/src/app/(studio)/marketing/loading.tsx b/src/app/(studio)/marketing/loading.tsx
index 9586d577..f79683d1 100644
--- a/src/app/(studio)/marketing/loading.tsx
+++ b/src/app/(studio)/marketing/loading.tsx
@@ -1,4 +1,4 @@
-import { MarketingSkeleton } from "@/components/skeletons";
+import { MarketingSkeleton } from "@/components/marketing/skeletons";
export default function Loading() {
return <MarketingSkeleton />;
diff --git a/src/app/(studio)/upscale/layout.tsx b/src/app/(studio)/upscale/layout.tsx
new file mode 100644
index 00000000..8bbee557
--- /dev/null
+++ b/src/app/(studio)/upscale/layout.tsx
@@ -0,0 +1,6 @@
+import { HubFrame } from "@/components/studio/hub-chrome";
+
+/** The hub's title bar and mode tabs: shared by /upscale and /upscale/<mode>, so a tab switch keeps them on screen. */
+export default function Layout({ children }: { children: React.ReactNode }) {
+ return <HubFrame kind="upscale">{children}</HubFrame>;
+}
diff --git a/src/app/(studio)/video-tools/layout.tsx b/src/app/(studio)/video-tools/layout.tsx
new file mode 100644
index 00000000..003f6aaa
--- /dev/null
+++ b/src/app/(studio)/video-tools/layout.tsx
@@ -0,0 +1,6 @@
+import { HubFrame } from "@/components/studio/hub-chrome";
+
+/** The hub's title bar and mode tabs: shared by /video-tools and /video-tools/<mode>, so a tab switch keeps them on screen. */
+export default function Layout({ children }: { children: React.ReactNode }) {
+ return <HubFrame kind="video-tools">{children}</HubFrame>;
+}
diff --git a/src/components/audio-tools/audio-tools.tsx b/src/components/audio-tools/audio-tools.tsx
index 0eda32e0..a391391c 100644
--- a/src/components/audio-tools/audio-tools.tsx
+++ b/src/components/audio-tools/audio-tools.tsx
@@ -310,7 +310,7 @@ function Results({ feature, title }: { feature: string; title: string }) {
}
/** Audio → Loop / extend. */
-export function AudioLoopTool({ tabs }: { tabs?: React.ReactNode }) {
+export function AudioLoopTool() {
const [engine, setEngine, mode] = useEngine();
const run = useAudioToolRun();
const [clip, setClip] = useState<Clip | null>(null);
@@ -334,7 +334,7 @@ export function AudioLoopTool({ tabs }: { tabs?: React.ReactNode }) {
run.mutate(body!, { onSuccess: () => toast.success("Looping…"), onError: (e) => toastError(e) });
};
return (
- <ToolShell title="Audio" tabs={tabs}>
+ <ToolShell title="Audio">
{!clip && (
<ToolHero
title="Make it as long as you need"
@@ -386,7 +386,7 @@ export function AudioLoopTool({ tabs }: { tabs?: React.ReactNode }) {
}
/** Audio → Join. */
-export function AudioJoinTool({ tabs }: { tabs?: React.ReactNode }) {
+export function AudioJoinTool() {
const [engine, setEngine, mode] = useEngine();
const run = useAudioToolRun();
const [clips, setClips] = useState<Clip[]>([]);
@@ -424,7 +424,7 @@ export function AudioJoinTool({ tabs }: { tabs?: React.ReactNode }) {
run.mutate(body!, { onSuccess: () => toast.success("Joining…"), onError: (e) => toastError(e) });
};
return (
- <ToolShell title="Audio" tabs={tabs}>
+ <ToolShell title="Audio">
{!clips.length && (
<ToolHero
title="Join clips into one track"
diff --git a/src/components/audio-tools/clean-voice-tool.tsx b/src/components/audio-tools/clean-voice-tool.tsx
index 47796be2..fc2263eb 100644
--- a/src/components/audio-tools/clean-voice-tool.tsx
+++ b/src/components/audio-tools/clean-voice-tool.tsx
@@ -197,7 +197,7 @@ function Row({ label, children, hint }: { label: string; children: React.ReactNo
const cleanOf = (g?: Generation | null): OutputFile | undefined => g?.outputs.find((o) => o.kind === "audio");
const reportOf = (g?: Generation | null): string | undefined => g?.outputs.find((o) => o.kind === "text")?.text;
-export function CleanVoiceTool({ tabs, app }: { tabs?: React.ReactNode; app?: { name: string; description: string } }) {
+export function CleanVoiceTool({ app }: { app?: { name: string; description: string } }) {
const [engine, setEngine, mode] = useEngine();
const run = useAudioToolRun();
const [source, setSource] = useState<Source | null>(null);
@@ -292,7 +292,6 @@ export function CleanVoiceTool({ tabs, app }: { tabs?: React.ReactNode; app?: {
return (
<ToolShell
title={app ? "Apps" : "Audio"}
- tabs={tabs}
header={
app ? (
<nav aria-label="Breadcrumb" className="hidden items-center gap-1 text-[13px] text-muted-foreground sm:flex">
diff --git a/src/components/audio-tools/design-voice-tool.tsx b/src/components/audio-tools/design-voice-tool.tsx
index 01e09ecf..aeb36461 100644
--- a/src/components/audio-tools/design-voice-tool.tsx
+++ b/src/components/audio-tools/design-voice-tool.tsx
@@ -126,7 +126,7 @@ function Take({ g, index, description, line, canSave }: { g: Generation; index:
);
}
-export function DesignVoiceTool({ tabs }: { tabs?: React.ReactNode }) {
+export function DesignVoiceTool() {
const [engine, setEngine, mode] = useEngine();
const visitor = useIsVisitor();
const create = useCreateGeneration();
@@ -171,7 +171,7 @@ export function DesignVoiceTool({ tabs }: { tabs?: React.ReactNode }) {
};
return (
- <ToolShell title="Audio" tabs={tabs}>
+ <ToolShell title="Audio">
<ToolHero title="Design a voice" subtitle="Describe who’s speaking. Hear three takes of your line, then save the one you like as a voice you can use anywhere." />
<div className="mx-auto mt-8 max-w-[820px] min-w-0 space-y-3">
<Panel title="The voice">
diff --git a/src/components/audio-tools/remove-dialogue-tool.tsx b/src/components/audio-tools/remove-dialogue-tool.tsx
index 4522a20c..eaec405d 100644
--- a/src/components/audio-tools/remove-dialogue-tool.tsx
+++ b/src/components/audio-tools/remove-dialogue-tool.tsx
@@ -375,7 +375,7 @@ function ResultPanel({
);
}
-export function RemoveDialogueTool({ tabs }: { tabs?: React.ReactNode }) {
+export function RemoveDialogueTool() {
const [engine, setEngine, mode] = useEngine();
// A guest or an account: the run answers own-gpu-tool, so the page says so and the upload and run are off.
const visitor = useLikelyVisitor();
@@ -467,7 +467,7 @@ export function RemoveDialogueTool({ tabs }: { tabs?: React.ReactNode }) {
: null;
return (
- <ToolShell title="Video tools" tabs={tabs} selfHostedOnly>
+ <ToolShell title="Video tools" selfHostedOnly>
{!source && (
<ToolHero
title="Remove dialogue"
diff --git a/src/components/audio-tools/split-tool.tsx b/src/components/audio-tools/split-tool.tsx
index df6b7e0c..e27cc1dc 100644
--- a/src/components/audio-tools/split-tool.tsx
+++ b/src/components/audio-tools/split-tool.tsx
@@ -681,7 +681,7 @@ function stemsOf(outputs: OutputFile[]): Stem[] {
});
}
-export function SplitSoundtrackTool({ tabs }: { tabs?: React.ReactNode }) {
+export function SplitSoundtrackTool() {
const [engine, setEngine, mode] = useEngine();
const visitor = useLikelyVisitor();
const run = useAudioToolRun();
@@ -749,7 +749,7 @@ export function SplitSoundtrackTool({ tabs }: { tabs?: React.ReactNode }) {
const stems = useMemo(() => (g?.status === "succeeded" ? stemsOf(g.outputs) : []), [g]);
return (
- <ToolShell title="Audio" tabs={tabs} selfHostedOnly>
+ <ToolShell title="Audio" selfHostedOnly>
{!source && (
<ToolHero
title="Split any soundtrack"
diff --git a/src/components/av/tool-shell.tsx b/src/components/av/tool-shell.tsx
index 68092428..367f9642 100644
--- a/src/components/av/tool-shell.tsx
+++ b/src/components/av/tool-shell.tsx
@@ -2,13 +2,15 @@
import { SidebarTrigger } from "@/components/ui/sidebar";
import { EngineSwitch } from "@/components/studio/engine-switch";
+import { HubHeaderExtras, useInHub } from "@/components/studio/hub-chrome";
import { useEngine } from "@/lib/api";
import { cn } from "@/lib/utils";
/**
* The frame of a stand-alone audio/video tool (Translate & dub, Captions, Trim, Katana, Image to 3D,
* Virality): the sticky header with the title, extra controls and the engine switch, an optional row
- * of hub tabs under it, then the page.
+ * of tabs under it, then the page. Inside a hub (Audio, Video tools) the hub's layout draws the title bar, the tabs and the
+ * engine switch; the tool adds only its own header controls to it.
*/
export function ToolShell({
title,
@@ -30,6 +32,15 @@ export function ToolShell({
wide?: boolean;
}) {
const [engine, setEngine] = useEngine();
+ const inHub = useInHub();
+ const body = <div className={cn("mx-auto w-full min-w-0 flex-1 px-3 pb-16 sm:px-6", wide ? "max-w-[1240px]" : "max-w-[1040px]")}>{children}</div>;
+ if (inHub)
+ return (
+ <>
+ {header && <HubHeaderExtras>{header}</HubHeaderExtras>}
+ {body}
+ </>
+ );
return (
<div className="flex min-h-svh min-w-0 flex-col">
<div className="sticky top-0 z-20 bg-background/85 backdrop-blur">
@@ -43,7 +54,7 @@ export function ToolShell({
</header>
{tabs}
</div>
- <div className={cn("mx-auto w-full min-w-0 flex-1 px-3 pb-16 sm:px-6", wide ? "max-w-[1240px]" : "max-w-[1040px]")}>{children}</div>
+ {body}
</div>
);
}
diff --git a/src/components/av/trim-tool.tsx b/src/components/av/trim-tool.tsx
index 13338e4c..5bfe3221 100644
--- a/src/components/av/trim-tool.tsx
+++ b/src/components/av/trim-tool.tsx
@@ -25,7 +25,7 @@ const MIN_LENGTH = 0.5;
* part (filmstrip, handles, play the selection, typed times); a clip the browser can't decode is
* trimmed by typed times, with its length read from the file when it says.
*/
-export function TrimTool({ tabs }: { tabs?: React.ReactNode }) {
+export function TrimTool() {
const [engine] = useEngine();
const create = useCreateGeneration();
const results = useGenerations({ features: [TRIM_FEATURE], limit: 24 });
@@ -87,7 +87,7 @@ export function TrimTool({ tabs }: { tabs?: React.ReactNode }) {
const typed = !!unread && unread.length == null;
const total = unread?.length ?? length;
return (
- <ToolShell title="Video tools" tabs={tabs}>
+ <ToolShell title="Video tools">
{!video && <ToolHero title="Keep just the part you need" subtitle="Pick where it starts and ends, and the sound comes along." />}
<div className={cn("mx-auto max-w-[820px] space-y-3", video ? "pt-4" : "mt-8")}>
<MediaDrop kind="video" value={video} onChange={pick} onFile={(f) => (dropped.current = f)} preview={false} title="Add a video to trim" hint="MP4, MOV or WebM up to 200 MB" compact />
diff --git a/src/components/captions/captions-studio.tsx b/src/components/captions/captions-studio.tsx
index 9ce0466e..a234af91 100644
--- a/src/components/captions/captions-studio.tsx
+++ b/src/components/captions/captions-studio.tsx
@@ -92,7 +92,7 @@ function download(name: string, text: string, type: string) {
}
/** Captions (Video tools → Captions): transcribe, fix every line, style, burn in — or export .srt / .vtt. */
-export function CaptionsStudio({ tabs }: { tabs?: React.ReactNode }) {
+export function CaptionsStudio() {
// The last project comes back after a reload (this browser only); a hand-off link wins. Both are read
// once mounted: on a link from Assist the address only changes as the new page commits, so reading
// it while rendering would still see /assist.
@@ -105,7 +105,7 @@ export function CaptionsStudio({ tabs }: { tabs?: React.ReactNode }) {
const video = picked === undefined ? (saved?.video ?? null) : picked;
const results = useGenerations({ features: ["captions"], kinds: ["video"], limit: 24 });
return (
- <ToolShell title="Video tools" tabs={tabs}>
+ <ToolShell title="Video tools">
{saved === undefined ? null : video && !video.uploading ? (
<Editor
key={video.ref}
diff --git a/src/components/dub/dub-studio.tsx b/src/components/dub/dub-studio.tsx
index 6b0c88c9..68b666b4 100644
--- a/src/components/dub/dub-studio.tsx
+++ b/src/components/dub/dub-studio.tsx
@@ -79,7 +79,7 @@ function StageBadge({ stage }: { stage: DubStage }) {
}
/** Translate & dub (Audio → Translate): a new dub, the dubs in progress and, opened, one dub's review. */
-export function DubStudio({ tabs }: { tabs?: React.ReactNode }) {
+export function DubStudio() {
const sessions = useDubSessions();
const [openId, setOpenId] = useState<string | null>(null);
// Hand-off: /audio/translate?dub=<id> opens that dub (Assist and MCP link the dubs they start).
@@ -99,7 +99,7 @@ export function DubStudio({ tabs }: { tabs?: React.ReactNode }) {
// A dub removed elsewhere (another tab) just closes.
const open = sessions.data?.find((s) => s.id === openId);
return (
- <ToolShell title="Audio" tabs={tabs} selfHostedOnly>
+ <ToolShell title="Audio" selfHostedOnly>
{open ? (
<SessionView key={open.id} s={open} onBack={() => show(null)} />
) : openId && sessions.isLoading ? (
diff --git a/src/components/evolution/evolution-tool.tsx b/src/components/evolution/evolution-tool.tsx
index 2975cdab..59ae52c5 100644
--- a/src/components/evolution/evolution-tool.tsx
+++ b/src/components/evolution/evolution-tool.tsx
@@ -54,7 +54,7 @@ async function frameDataUrl(blob: Blob | null | undefined): Promise<string | und
* and a creative direction you write or an LLM writes from the references; priced before it runs ("Free" on your
* GPU); the result with a before / after wipe.
*/
-export function EvolutionTool({ tabs }: { tabs?: React.ReactNode }) {
+export function EvolutionTool() {
const [engine] = useEngine();
// Evolution doesn't run on an account's own GPU or key yet (only the studios' generations do): said up front, and
// the upload and Evolve are off, instead of a run the server refuses.
@@ -159,7 +159,7 @@ export function EvolutionTool({ tabs }: { tabs?: React.ReactNode }) {
};
return (
- <ToolShell title="Video tools" tabs={tabs} wide selfHostedOnly>
+ <ToolShell title="Video tools" wide selfHostedOnly>
{!clip && (
<ToolHero
title="Take a clip further"
diff --git a/src/components/marketing/shell.tsx b/src/components/marketing/shell.tsx
index 9a25368a..3c4a5e21 100644
--- a/src/components/marketing/shell.tsx
+++ b/src/components/marketing/shell.tsx
@@ -8,6 +8,7 @@ import { EngineSwitch } from "@/components/studio/engine-switch";
import { useEngine } from "@/lib/api";
import type { Engine } from "@/lib/catalog/types";
import { cn } from "@/lib/utils";
+import { isPlainClick, useTappedTab } from "@/lib/use-tapped-tab";
export type SuiteTab = "studio" | "click" | "ads" | "multiplier";
@@ -38,6 +39,10 @@ export function MarketingHeader({
selfHostedOnly?: boolean;
}) {
const nav = useRef<HTMLElement>(null);
+ // Each tool's page draws this header: the tab tapped here is the current one from the next frame on, until the new page
+ // (with its own header) replaces this one.
+ const [tapped, tap] = useTappedTab<SuiteTab>(active);
+ const current = tapped ?? active;
// On a phone the tabs scroll sideways: bring the current one into view.
useEffect(() => {
const el = nav.current?.querySelector<HTMLElement>('[aria-current="page"]');
@@ -60,10 +65,11 @@ export function MarketingHeader({
<Link
key={t.id}
href={t.href}
- aria-current={t.id === active ? "page" : undefined}
+ aria-current={t.id === current ? "page" : undefined}
+ onClick={(e) => isPlainClick(e) && tap(t.id)}
className={cn(
"inline-flex h-9 shrink-0 items-center gap-1.5 border-b-2 border-transparent px-2.5 text-[13px] font-medium whitespace-nowrap text-muted-foreground transition-colors hover:text-foreground",
- t.id === active && "border-primary text-foreground",
+ t.id === current && "border-primary text-foreground",
)}
>
<t.icon className="size-3.5" />
diff --git a/src/components/marketing/skeletons.tsx b/src/components/marketing/skeletons.tsx
new file mode 100644
index 00000000..273d3813
--- /dev/null
+++ b/src/components/marketing/skeletons.tsx
@@ -0,0 +1,65 @@
+import { Skeleton } from "@/components/ui/skeleton";
+import { MarketingHeader, type SuiteTab } from "./shell";
+
+/*
+ * Route skeletons (loading.tsx) of the marketing suite: Marketing Studio, Click to Ad, Ads Studio and Ad Multiplier.
+ */
+
+/**
+ * The marketing suite's real header (title and the four tool tabs, the page's own tab current) over a page skeleton: the
+ * tabs stay on screen while a tool that wasn't prefetched yet loads.
+ */
+function MarketingFrame({ title, active, children }: { title: string; active: SuiteTab; children: React.ReactNode }) {
+ return (
+ <div className="flex min-h-svh min-w-0 flex-col">
+ <MarketingHeader title={title} active={active} right={<Skeleton className="h-9 w-40 rounded-full max-sm:w-20" />} />
+ <div className="flex min-w-0 flex-1 flex-col" aria-busy="true" aria-label="Loading">
+ {children}
+ </div>
+ </div>
+ );
+}
+
+/** A marketing tool (Click to Ad, Ads Studio, Ad Multiplier): the suite's header and tabs, the hero line and the main box. */
+export function MarketingToolSkeleton({ title, active }: { title: string; active: SuiteTab }) {
+ return (
+ <MarketingFrame title={title} active={active}>
+ <div className="mx-auto flex w-full max-w-[760px] flex-col items-center px-3 pt-8 sm:px-6 sm:pt-[10vh]">
+ <Skeleton className="h-9 w-2/3 max-w-[420px] rounded-xl" />
+ <Skeleton className="mt-3 h-4 w-1/2 max-w-[300px]" />
+ <Skeleton className="mt-10 h-40 w-full rounded-[20px]" />
+ </div>
+ </MarketingFrame>
+ );
+}
+
+/** Marketing Studio: the suite's header and tabs, the hero, the template grid and the docked composer. */
+export function MarketingSkeleton() {
+ return (
+ <MarketingFrame title="Marketing Studio" active="studio">
+ <div className="mx-auto w-full max-w-[1240px] flex-1 px-3 sm:px-6">
+ <div className="flex flex-col items-center pt-6 pb-2 sm:pt-10">
+ <Skeleton className="h-10 w-3/4 max-w-[560px] rounded-xl" />
+ <Skeleton className="mt-3 h-4 w-2/3 max-w-[420px]" />
+ <Skeleton className="mt-6 h-9 w-56 rounded-full" />
+ </div>
+ <div className="mt-6 flex gap-1.5 overflow-hidden">
+ {Array.from({ length: 8 }, (_, i) => (
+ <Skeleton key={i} className="h-8 w-24 shrink-0 rounded-full" />
+ ))}
+ </div>
+ <div className="mt-4 grid grid-cols-2 gap-x-3 gap-y-5 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5">
+ {Array.from({ length: 10 }, (_, i) => (
+ <div key={i} className="space-y-2">
+ <Skeleton className="aspect-[3/4] rounded-2xl" />
+ <Skeleton className="h-3.5 w-2/3" />
+ </div>
+ ))}
+ </div>
+ </div>
+ <div className="sticky bottom-0 px-3 pb-3 sm:px-6">
+ <Skeleton className="mx-auto h-14 w-full max-w-[860px] rounded-[20px] sm:rounded-composer" />
+ </div>
+ </MarketingFrame>
+ );
+}
diff --git a/src/components/remove-object/remove-object-tool.tsx b/src/components/remove-object/remove-object-tool.tsx
index ca5d2932..0ef7a8f8 100644
--- a/src/components/remove-object/remove-object-tool.tsx
+++ b/src/components/remove-object/remove-object-tool.tsx
@@ -70,7 +70,7 @@ interface Run {
* result with a before / after wipe. Long clips are cut into pieces or windows, erased and joined with their
* own sound (src/lib/catalog/remove-object.ts).
*/
-export function RemoveObjectTool({ tabs }: { tabs?: React.ReactNode }) {
+export function RemoveObjectTool() {
const [engine, setEngine, engineMode] = useEngine();
// Removing an object doesn't run on an account's own GPU or key yet (only the studios' generations do): said up front,
// and the upload, the mask preview and Remove are off, instead of a run the server refuses.
@@ -239,7 +239,7 @@ export function RemoveObjectTool({ tabs }: { tabs?: React.ReactNode }) {
const preview = useGeneration(previewOf?.id ?? null).data;
return (
- <ToolShell title="Video tools" tabs={tabs} wide selfHostedOnly>
+ <ToolShell title="Video tools" wide selfHostedOnly>
{!clip && (
<ToolHero
title="Remove anything from a video"
diff --git a/src/components/restore/restore-tool.tsx b/src/components/restore/restore-tool.tsx
index 0bd7dfcd..1f811931 100644
--- a/src/components/restore/restore-tool.tsx
+++ b/src/components/restore/restore-tool.tsx
@@ -44,7 +44,7 @@ interface Run {
* to 4K, deinterlacing and a reference picture; priced before it runs ("Free" on your GPU); the result with a before /
* after wipe. A clip handed over from the Library or a result arrives as ?video=.
*/
-export function RestoreTool({ tabs }: { tabs?: React.ReactNode }) {
+export function RestoreTool() {
const [engine] = useEngine();
// Guests and free accounts: it plans with the studio's own AI helpers and joins on the server (own-gpu-tool).
const visitor = useLikelyVisitor();
@@ -146,7 +146,7 @@ export function RestoreTool({ tabs }: { tabs?: React.ReactNode }) {
};
return (
- <ToolShell title="Video tools" tabs={tabs} wide selfHostedOnly>
+ <ToolShell title="Video tools" wide selfHostedOnly>
{!clip && (
<ToolHero
title="Restore & colourise"
diff --git a/src/components/skeletons.tsx b/src/components/skeletons.tsx
index 186e0e2b..b168dd4c 100644
--- a/src/components/skeletons.tsx
+++ b/src/components/skeletons.tsx
@@ -31,6 +31,27 @@ export function StudioSkeleton() {
);
}
+/**
+ * A hub mode's body (under the hub's own title bar and tabs, which stay on screen): the hero line and the main box, where
+ * every mode has them. Shown only while a mode that wasn't prefetched yet loads.
+ */
+export function HubBodySkeleton() {
+ return (
+ <div className="mx-auto flex w-full max-w-[760px] flex-col items-center px-3 pt-6 sm:px-6 sm:pt-[12vh]" aria-busy="true" aria-label="Loading" data-hub-skeleton>
+ <Skeleton className="h-9 w-2/3 max-w-[420px] rounded-xl" />
+ <Skeleton className="mt-3 h-4 w-1/2 max-w-[300px]" />
+ <div className="mt-10 w-full rounded-[20px] border bg-background p-2.5 shadow-soft sm:rounded-composer">
+ <Skeleton className="h-14 w-full rounded-xl bg-muted/60" />
+ <div className="mt-2 flex items-center gap-1.5">
+ <Skeleton className="h-8 w-28 rounded-full" />
+ <Skeleton className="h-8 w-16 rounded-full" />
+ <Skeleton className="ml-auto size-10 rounded-full" />
+ </div>
+ </div>
+ </div>
+ );
+}
+
export const GALLERY_GRID = "grid grid-cols-2 gap-1 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5";
/** Gallery body: filter row, category strip, card grid. */
@@ -89,44 +110,3 @@ export function PageSkeleton({ title, wide, rows = 4 }: { title?: string; wide?:
);
}
-/** Marketing Studio: header with its tool tabs, the hero, the template grid and the docked composer. */
-export function MarketingSkeleton() {
- return (
- <div className="flex min-h-svh min-w-0 flex-col" aria-busy="true" aria-label="Loading">
- <div className="sticky top-0 z-20 bg-background/85 px-3 sm:px-6">
- <div className="flex h-14 items-center gap-2">
- <Skeleton className="h-6 w-44 rounded-lg" />
- <Skeleton className="ml-auto h-9 w-40 rounded-full max-sm:w-20" />
- </div>
- <div className="flex gap-2 overflow-hidden pb-2">
- {Array.from({ length: 5 }, (_, i) => (
- <Skeleton key={i} className="h-7 w-24 shrink-0 rounded-full" />
- ))}
- </div>
- </div>
- <div className="mx-auto w-full max-w-[1240px] flex-1 px-3 sm:px-6">
- <div className="flex flex-col items-center pt-6 pb-2 sm:pt-10">
- <Skeleton className="h-10 w-3/4 max-w-[560px] rounded-xl" />
- <Skeleton className="mt-3 h-4 w-2/3 max-w-[420px]" />
- <Skeleton className="mt-6 h-9 w-56 rounded-full" />
- </div>
- <div className="mt-6 flex gap-1.5 overflow-hidden">
- {Array.from({ length: 8 }, (_, i) => (
- <Skeleton key={i} className="h-8 w-24 shrink-0 rounded-full" />
- ))}
- </div>
- <div className="mt-4 grid grid-cols-2 gap-x-3 gap-y-5 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5">
- {Array.from({ length: 10 }, (_, i) => (
- <div key={i} className="space-y-2">
- <Skeleton className="aspect-[3/4] rounded-2xl" />
- <Skeleton className="h-3.5 w-2/3" />
- </div>
- ))}
- </div>
- </div>
- <div className="sticky bottom-0 px-3 pb-3 sm:px-6">
- <Skeleton className="mx-auto h-14 w-full max-w-[860px] rounded-[20px] sm:rounded-composer" />
- </div>
- </div>
- );
-}
diff --git a/src/components/studio/hub-chrome.tsx b/src/components/studio/hub-chrome.tsx
new file mode 100644
index 00000000..a9c82d3d
--- /dev/null
+++ b/src/components/studio/hub-chrome.tsx
@@ -0,0 +1,165 @@
+"use client";
+
+import Link from "next/link";
+import { usePathname, useRouter } from "next/navigation";
+import { createContext, Suspense, useContext, useEffect, useMemo, useRef, useState } from "react";
+import { createPortal } from "react-dom";
+import type { PrefetchOptions } from "next/dist/shared/lib/app-router-context.shared-runtime";
+import { SidebarTrigger } from "@/components/ui/sidebar";
+import { EngineSwitch } from "@/components/studio/engine-switch";
+import { useEngine, useLikelyVisitor } from "@/lib/api";
+import { HUB_MODES, HUB_TITLE, hubOfPath, modeHref, modeOfPath, type HubKind } from "@/lib/hubs";
+import { cn } from "@/lib/utils";
+import { isPlainClick, useTappedTab } from "@/lib/use-tapped-tab";
+import { whenIdle } from "@/lib/when-idle";
+import { useEdgeFade } from "./use-edge-fade";
+
+/**
+ * The frame of a hub (Audio, Video tools, Upscale): the sticky title bar and the mode tabs live in the hub's layout, shared
+ * by /<hub> and every /<hub>/<mode>, so they stay on screen while a tab's page loads ("layouts preserve state, remain
+ * interactive, and do not rerender"). Each mode's page draws only its body, and puts its own header controls (the GPU
+ * pill, a tool's extra buttons) into the bar with <HubHeaderExtras>.
+ */
+
+const HubCtx = createContext<{ slot: HTMLElement | null } | null>(null);
+
+/** Inside a hub's frame: the page leaves the title bar and tabs to it. */
+export function useInHub(): boolean {
+ return useContext(HubCtx) !== null;
+}
+
+/** A page's own header controls, shown in the hub's title bar left of the engine switch. */
+export function HubHeaderExtras({ children }: { children: React.ReactNode }) {
+ const slot = useContext(HubCtx)?.slot;
+ return slot ? createPortal(children, slot) : null;
+}
+
+/** `<Link prefetch={true}>` for a link that isn't on screen: the per-link prefetch of a whole (prerendered) mode page. */
+const FULL = { kind: "full" } as unknown as PrefetchOptions;
+
+/**
+ * The hub's mode tabs: underline tabs on their own row under the title; they scroll sideways (with faded edges) on
+ * phones. Each mode is its own history entry, so Back returns to the mode before.
+ *
+ * Instant by design: the tapped tab is marked at once (before the route commits), every tab prefetches its whole mode
+ * page (each is prerendered, so the prefetch comes from the static cache), and the tabs a phone's row scrolls out of
+ * view are prefetched too once the page is idle: a tap then renders the mode from the client cache, with no blank frame.
+ */
+function HubTabs({ kind, pathname, onActive }: { kind: HubKind; pathname: string | null; onActive?: (mode: string) => void }) {
+ const router = useRouter();
+ const [ref, fade] = useEdgeFade<HTMLDivElement>();
+ const activeRef = useRef<HTMLAnchorElement>(null);
+ const visitor = useLikelyVisitor();
+ // The tab just tapped: the current one from the next frame on, until the route moves (then the path says).
+ const [tapped, tap] = useTappedTab<string>(pathname);
+ const shown = pathname ? modeOfPath(kind, pathname) : undefined;
+ const active = tapped ?? shown;
+ const modes = visitor ? HUB_MODES[kind].filter((m) => !m.ownerOnly || m.id === shown) : HUB_MODES[kind];
+
+ useEffect(() => {
+ if (active) onActive?.(active);
+ }, [active, onActive]);
+
+ // Keep the selected tab in view when the row scrolls (only the row: the page stays put).
+ useEffect(() => {
+ const el = activeRef.current;
+ const row = ref.current;
+ if (!el || !row) return;
+ const left = el.offsetLeft - row.offsetLeft;
+ if (left < row.scrollLeft || left + el.offsetWidth > row.scrollLeft + row.clientWidth) row.scrollLeft = left - 12;
+ }, [active, ref]);
+
+ // Every mode, also the ones scrolled out of the row, once the page is idle (a tab on screen already prefetches itself).
+ // Once per hub and audience: the client cache keeps what was fetched.
+ const hrefs = modes.map((m) => modeHref(kind, m.id)).join(" ");
+ useEffect(() => whenIdle(() => hrefs.split(" ").forEach((href) => router.prefetch(href, FULL))), [hrefs, router]);
+
+ return (
+ <nav aria-label="Modes" className="border-b">
+ <div ref={ref} style={fade} className="scrollbar-none flex gap-1 overflow-x-auto px-3 sm:px-6">
+ {modes.map((m) => {
+ const on = m.id === active;
+ const href = modeHref(kind, m.id);
+ return (
+ <Link
+ key={m.id}
+ ref={on ? activeRef : undefined}
+ href={href}
+ prefetch
+ scroll={false}
+ data-mode={m.id}
+ onTouchStart={() => router.prefetch(href, FULL)}
+ // A new tab or window (modifier, middle button) leaves this page as it is.
+ onClick={(e) => isPlainClick(e) && tap(m.id)}
+ aria-current={on ? "page" : undefined}
+ className={cn(
+ "relative flex h-10 shrink-0 items-center rounded-md px-2.5 text-[13px] font-medium whitespace-nowrap text-muted-foreground transition-colors outline-none hover:text-foreground focus-visible:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",
+ "after:absolute after:inset-x-2.5 after:bottom-0 after:h-0.5 after:rounded-full focus-visible:after:bg-ring",
+ on && "text-foreground after:bg-foreground",
+ )}
+ >
+ {m.label}
+ </Link>
+ );
+ })}
+ </div>
+ </nav>
+ );
+}
+
+/** Reads the path (runtime data while a route prerenders) inside Suspense; the fallback is the same row, unselected. */
+function PathTabs({ kind, onActive }: { kind: HubKind; onActive: (mode: string) => void }) {
+ const pathname = usePathname();
+ return <HubTabs kind={kind} pathname={pathname} onActive={onActive} />;
+}
+
+function HubEngine({ kind, mode }: { kind: HubKind; mode: string | undefined }) {
+ const [engine, setEngine] = useEngine();
+ const selfHostedOnly = !!HUB_MODES[kind].find((m) => m.id === mode)?.selfHostedOnly;
+ return <EngineSwitch value={engine} onChange={setEngine} selfHostedOnly={selfHostedOnly} />;
+}
+
+/** The title bar and the tabs of a hub. `children`: the mode's page (or, while a route loads, its skeleton). */
+export function HubFrame({ kind, children }: { kind: HubKind; children: React.ReactNode }) {
+ const [slot, setSlot] = useState<HTMLElement | null>(null);
+ const [mode, setMode] = useState<string | undefined>(undefined);
+ const ctx = useMemo(() => ({ slot }), [slot]);
+ return (
+ <div className="flex min-h-svh min-w-0 flex-col" data-hub={kind}>
+ <div className="sticky top-0 z-20 bg-background/85 backdrop-blur" data-hub-chrome>
+ <header className="flex h-14 items-center gap-2 px-3 sm:px-6">
+ <SidebarTrigger className="md:hidden" />
+ <h1 className="min-w-0 truncate font-heading text-[22px] leading-[1.15]">{HUB_TITLE[kind]}</h1>
+ <div className="ml-auto flex shrink-0 items-center gap-2">
+ <div ref={setSlot} className="contents" />
+ <HubEngine kind={kind} mode={mode} />
+ </div>
+ </header>
+ <Suspense fallback={<HubTabs kind={kind} pathname={null} />}>
+ <PathTabs kind={kind} onActive={setMode} />
+ </Suspense>
+ </div>
+ <HubCtx.Provider value={ctx}>
+ <div className="flex min-w-0 flex-1 flex-col" data-hub-body>{children}</div>
+ </HubCtx.Provider>
+ </div>
+ );
+}
+
+function PathSkeleton({ generic, hubBody }: { generic: React.ReactNode; hubBody: React.ReactNode }) {
+ const hub = hubOfPath(usePathname());
+ return hub ? <HubFrame kind={hub}>{hubBody}</HubFrame> : generic;
+}
+
+/**
+ * The studio's route skeleton (loading.tsx), for a page whose shell wasn't prefetched yet: on the way into a hub it is
+ * the hub's real title bar and tabs (the new mode already marked) over the body's skeleton, so nothing moves when the
+ * page arrives; elsewhere the generic one.
+ */
+export function StudioRouteSkeleton({ generic, hubBody }: { generic: React.ReactNode; hubBody: React.ReactNode }) {
+ return (
+ <Suspense fallback={generic}>
+ <PathSkeleton generic={generic} hubBody={hubBody} />
+ </Suspense>
+ );
+}
diff --git a/src/components/studio/mode-studio.tsx b/src/components/studio/mode-studio.tsx
deleted file mode 100644
index 4244cc39..00000000
--- a/src/components/studio/mode-studio.tsx
+++ /dev/null
@@ -1,89 +0,0 @@
-"use client";
-
-import Link from "next/link";
-import { useEffect, useRef } from "react";
-import type { StudioCatalog } from "@/lib/studio-catalog";
-import type { StudioExampleRow } from "@/lib/studio-examples";
-import { useLikelyVisitor } from "@/lib/api";
-import { cn } from "@/lib/utils";
-import { StudioPage } from "./studio-page";
-import type { StudioConfig } from "./studio-context";
-import { useEdgeFade } from "./use-edge-fade";
-
-export interface ModeTab {
- id: string;
- label: string;
- href: string;
- /** Left out for a guest or an account (a tool that runs on a self-hosted Fuobe only), unless it is the page shown. */
- ownerOnly?: true;
-}
-
-/** A tab chosen with the keyboard: the next mode's tabs (each mode's page draws its own) take the focus back. */
-let refocus = false;
-
-/**
- * Underline tabs on their own row under the page title; they scroll sideways (with faded edges) on phones. Each mode is
- * its own history entry, so Back returns to the mode before.
- */
-export function ModeTabs({ tabs, current }: { tabs: ModeTab[]; current: string }) {
- const [ref, fade] = useEdgeFade<HTMLDivElement>();
- const active = useRef<HTMLAnchorElement>(null);
- const visitor = useLikelyVisitor();
- const shown = visitor ? tabs.filter((m) => !m.ownerOnly || m.id === current) : tabs;
- // Keep the selected tab in view when the row scrolls (only the row: the page stays put).
- useEffect(() => {
- const el = active.current;
- const row = ref.current;
- if (!el || !row) return;
- const left = el.offsetLeft - row.offsetLeft;
- if (left < row.scrollLeft || left + el.offsetWidth > row.scrollLeft + row.clientWidth) row.scrollLeft = left - 12;
- if (refocus) {
- refocus = false;
- el.focus({ preventScroll: true });
- }
- }, [current, ref]);
- return (
- <nav aria-label="Modes" className="border-b">
- <div ref={ref} style={fade} className="scrollbar-none flex gap-1 overflow-x-auto px-3 sm:px-6">
- {shown.map((m) => {
- const on = m.id === current;
- return (
- <Link
- key={m.id}
- ref={on ? active : undefined}
- href={m.href}
- scroll={false}
- // A keyboard's Enter is a click with no pointer (detail 0).
- onClick={(e) => (refocus = e.detail === 0)}
- aria-current={on ? "page" : undefined}
- className={cn(
- "relative flex h-10 shrink-0 items-center rounded-md px-2.5 text-[13px] font-medium whitespace-nowrap text-muted-foreground transition-colors outline-none hover:text-foreground focus-visible:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",
- "after:absolute after:inset-x-2.5 after:bottom-0 after:h-0.5 after:rounded-full after:transition-colors focus-visible:after:bg-ring",
- on && "text-foreground after:bg-foreground",
- )}
- >
- {m.label}
- </Link>
- );
- })}
- </div>
- </nav>
- );
-}
-
-/** One mode of a hub (Audio, Video tools, Upscale): its studio with the hub's tabs. Each mode has its own path. */
-export function ModeStudio({
- tabs,
- current,
- config,
- catalog,
- examples,
-}: {
- tabs: ModeTab[];
- current: string;
- config: StudioConfig;
- catalog: StudioCatalog;
- examples?: StudioExampleRow;
-}) {
- return <StudioPage config={config} catalog={catalog} tabs={<ModeTabs tabs={tabs} current={current} />} examples={examples} />;
-}
diff --git a/src/components/studio/mode-switch-studio.tsx b/src/components/studio/mode-switch-studio.tsx
index 0e369ce2..0e4fe6d7 100644
--- a/src/components/studio/mode-switch-studio.tsx
+++ b/src/components/studio/mode-switch-studio.tsx
@@ -23,7 +23,7 @@ import {
VOICE_CHANGE_STUDIO,
} from "@/lib/studios";
import { studioCatalog } from "@/lib/studio-catalog";
-import { HUB_MODES, modeHref, type HubKind } from "@/lib/hubs";
+import { HUB_MODES, HUB_TITLE, type HubKind } from "@/lib/hubs";
import { CaptionsStudio } from "@/components/captions/captions-studio";
import { DubStudio } from "@/components/dub/dub-studio";
import { TrimTool } from "@/components/av/trim-tool";
@@ -35,7 +35,8 @@ import { SplitSoundtrackTool } from "@/components/audio-tools/split-tool";
import { RemoveDialogueTool } from "@/components/audio-tools/remove-dialogue-tool";
import { CleanVoiceTool } from "@/components/audio-tools/clean-voice-tool";
import { DesignVoiceTool } from "@/components/audio-tools/design-voice-tool";
-import { ModeStudio, ModeTabs } from "./mode-studio";
+import { HubBodySkeleton } from "@/components/skeletons";
+import { StudioPage } from "./studio-page";
import type { StudioConfig } from "./studio-context";
const CONFIGS: Record<HubKind, Record<string, StudioConfig>> = {
@@ -60,40 +61,37 @@ const CONFIGS: Record<HubKind, Record<string, StudioConfig>> = {
};
/** Modes that are their own tool rather than a composer studio (Translate & dub, Loop / extend, Join, Split soundtrack, Clean up voice, Design a voice, Remove object, Remove dialogue, Evolution, Restore & colourise, Captions, Trim). */
-const TOOLS: Partial<Record<HubKind, Record<string, (p: { tabs: React.ReactNode }) => React.ReactNode>>> = {
+const TOOLS: Partial<Record<HubKind, Record<string, () => React.ReactNode>>> = {
audio: {
- translate: ({ tabs }) => <DubStudio tabs={tabs} />,
- loop: ({ tabs }) => <AudioLoopTool tabs={tabs} />,
- join: ({ tabs }) => <AudioJoinTool tabs={tabs} />,
- split: ({ tabs }) => <SplitSoundtrackTool tabs={tabs} />,
- clean: ({ tabs }) => <CleanVoiceTool tabs={tabs} />,
- design: ({ tabs }) => <DesignVoiceTool tabs={tabs} />,
+ translate: () => <DubStudio />,
+ loop: () => <AudioLoopTool />,
+ join: () => <AudioJoinTool />,
+ split: () => <SplitSoundtrackTool />,
+ clean: () => <CleanVoiceTool />,
+ design: () => <DesignVoiceTool />,
},
"video-tools": {
- "remove-object": ({ tabs }) => <RemoveObjectTool tabs={tabs} />,
- "remove-dialogue": ({ tabs }) => <RemoveDialogueTool tabs={tabs} />,
- evolution: ({ tabs }) => <EvolutionTool tabs={tabs} />,
- restore: ({ tabs }) => <RestoreTool tabs={tabs} />,
- captions: ({ tabs }) => <CaptionsStudio tabs={tabs} />,
- trim: ({ tabs }) => <TrimTool tabs={tabs} />,
+ "remove-object": () => <RemoveObjectTool />,
+ "remove-dialogue": () => <RemoveDialogueTool />,
+ evolution: () => <EvolutionTool />,
+ restore: () => <RestoreTool />,
+ captions: () => <CaptionsStudio />,
+ trim: () => <TrimTool />,
},
};
-const HUB_TITLE: Record<HubKind, string> = { upscale: "Upscale", audio: "Audio", "video-tools": "Video tools" };
-
/**
- * A hub of studios with one path per mode (Audio → /audio/music, Video tools, Upscale). Server
- * component: the page is prerendered with that mode's hero, tabs and composer, and ships only
- * that mode's models. `mode` omitted = the first mode (the hub's own URL).
+ * One mode of a hub (Audio → /audio/music, Video tools, Upscale). Server component: the page is prerendered with that
+ * mode's hero and composer, and ships only that mode's models. The hub's title bar and tabs are its layout's
+ * (HubFrame). `mode` omitted = the first mode (the hub's own URL).
*/
export function ModeSwitchStudio({ kind, mode, examples }: { kind: HubKind; mode?: string; examples?: StudioExampleRow }) {
const current = mode ?? HUB_MODES[kind][0].id;
- const tabs = HUB_MODES[kind].map((m) => ({ id: m.id, label: m.label, href: modeHref(kind, m.id), ...(m.ownerOnly && { ownerOnly: true as const }) }));
const Tool = TOOLS[kind]?.[current];
- if (Tool) return <Tool tabs={<ModeTabs tabs={tabs} current={current} />} />;
+ if (Tool) return <Tool />;
const config = CONFIGS[kind][current];
if (!config) notFound();
- return <ModeStudio key={current} tabs={tabs} current={current} config={config} catalog={studioCatalog(config)} examples={examples} />;
+ return <StudioPage config={config} catalog={studioCatalog(config)} examples={examples} />;
}
/** `generateStaticParams` for /<hub>/[mode]: every mode is prerendered. */
@@ -106,7 +104,10 @@ export function hubMetadata(kind: HubKind, mode: string): Metadata {
return { title: !m || m.id === HUB_MODES[kind][0].id ? HUB_TITLE[kind] : `${m.label} · ${HUB_TITLE[kind]}` };
}
-/** The /<hub>/[mode] page body. */
+/**
+ * The /<hub>/[mode] page body. `params` is URL data, so the shared App Shell of the route holds only the fallback (the
+ * hub's tabs prefetch each mode's whole page, so a tap rarely sees it); it is the body's skeleton under the hub's bar.
+ */
export function HubModePage({ kind, params }: { kind: HubKind; params: Promise<{ mode: string }> }) {
- return <Suspense fallback={null}>{params.then(({ mode }) => <ModeSwitchStudio kind={kind} mode={mode} />)}</Suspense>;
+ return <Suspense fallback={<HubBodySkeleton />}>{params.then(({ mode }) => <ModeSwitchStudio kind={kind} mode={mode} />)}</Suspense>;
}
diff --git a/src/components/studio/studio-page.tsx b/src/components/studio/studio-page.tsx
index ff8422ad..2ed3c5c6 100644
--- a/src/components/studio/studio-page.tsx
+++ b/src/components/studio/studio-page.tsx
@@ -41,6 +41,7 @@ import { ComposerBridgeCtx, useComposerBridge, type ComposerBridge } from "./att
import { CatalogProvider, useCatalog } from "./catalog";
import { Composer } from "./composer";
import { EngineSwitch } from "./engine-switch";
+import { HubHeaderExtras, useInHub } from "./hub-chrome";
import { Feed } from "./feed";
import type { SlotValue } from "./media-slot";
import { PresetUrlCtx, StartRequestCtx, StudioProvider, usePresetUrl, useStudio, useStudioActions, type Draft, type StudioConfig } from "./studio-context";
@@ -408,9 +409,20 @@ function StudioGpuPill() {
return <HeaderPill badge={badge} gpu={badges.gpu} compact onOpen={() => openGpuSetup({ ref })} />;
}
-/** Sticky page header (title + engine), with an optional row of mode tabs under it. */
+/**
+ * Sticky page header (title + engine), with an optional row of mode tabs under it. Inside a hub (Audio, Upscale) the hub's
+ * layout draws the bar, the tabs and the engine switch, so they stay put across modes: the studio adds only its own controls.
+ */
function StudioHeader({ title, header, tabs }: { title: string; header?: React.ReactNode; tabs?: React.ReactNode }) {
const [engine, setEngine] = useEngine();
+ const inHub = useInHub();
+ if (inHub)
+ return (
+ <HubHeaderExtras>
+ {header}
+ <StudioGpuPill />
+ </HubHeaderExtras>
+ );
return (
<div className="sticky top-0 z-20 bg-background/85 backdrop-blur">
<header className="flex h-14 items-center gap-2 px-3 sm:px-6">
@@ -445,6 +457,7 @@ function StudioBody({ header, tabs, examples }: { header?: React.ReactNode; tabs
const offscreen = useOffscreenResults(feed.data);
const catalog = useCatalog();
const [live, setLive] = useState(false);
+ const inHub = useInHub();
const reuse = useCallback(
(g: Generation) => {
@@ -462,7 +475,7 @@ function StudioBody({ header, tabs, examples }: { header?: React.ReactNode; tabs
return (
<div
data-studio
- className="relative flex min-h-svh min-w-0 flex-col"
+ className={cn("relative flex min-w-0 flex-col", inHub ? "flex-1" : "min-h-svh")}
onDragEnter={(e) => {
if (![...e.dataTransfer.types].includes("Files")) return;
dragDepth.current++;
diff --git a/src/lib/hubs.ts b/src/lib/hubs.ts
index 36c82ffe..44dec5c2 100644
--- a/src/lib/hubs.ts
+++ b/src/lib/hubs.ts
@@ -5,11 +5,21 @@
*/
export type HubKind = "audio" | "video-tools" | "upscale";
-/**
- * ownerOnly: a mode a guest or an account doesn't see at all (its tab is left out for them). A tool that runs on a
- * self-hosted Fuobe only keeps its tab, and its page says up front that it isn't available here.
- */
-export const HUB_MODES: Record<HubKind, { id: string; label: string; ownerOnly?: true }[]> = {
+export interface HubMode {
+ id: string;
+ label: string;
+ /**
+ * A mode a guest or an account doesn't see at all (its tab is left out for them). A tool that runs on a self-hosted
+ * Fuobe only keeps its tab, and its page says up front that it isn't available here.
+ */
+ ownerOnly?: true;
+ /** The mode's tool runs on a self-hosted Fuobe only: the hub's engine badge says so to anyone but the owner (EngineSwitch). */
+ selfHostedOnly?: true;
+}
+
+export const HUB_TITLE: Record<HubKind, string> = { upscale: "Upscale", audio: "Audio", "video-tools": "Video tools" };
+
+export const HUB_MODES: Record<HubKind, HubMode[]> = {
upscale: [
{ id: "image", label: "Image" },
{ id: "video", label: "Video" },
@@ -22,10 +32,10 @@ export const HUB_MODES: Record<HubKind, { id: string; label: string; ownerOnly?:
{ id: "dialogue", label: "Dialogue" },
{ id: "voice-change", label: "Voice change" },
{ id: "design", label: "Design a voice" },
- { id: "translate", label: "Translate" },
+ { id: "translate", label: "Translate", selfHostedOnly: true },
{ id: "transcribe", label: "Transcribe" },
{ id: "clean", label: "Clean up voice" },
- { id: "split", label: "Split soundtrack" },
+ { id: "split", label: "Split soundtrack", selfHostedOnly: true },
{ id: "sfx", label: "Sound effects" },
{ id: "music", label: "Music" },
{ id: "loop", label: "Loop / extend" },
@@ -34,10 +44,10 @@ export const HUB_MODES: Record<HubKind, { id: string; label: string; ownerOnly?:
],
"video-tools": [
{ id: "matte", label: "Remove background" },
- { id: "remove-object", label: "Remove object" },
- { id: "remove-dialogue", label: "Remove dialogue" },
- { id: "evolution", label: "Evolution" },
- { id: "restore", label: "Restore & colourise", ownerOnly: true },
+ { id: "remove-object", label: "Remove object", selfHostedOnly: true },
+ { id: "remove-dialogue", label: "Remove dialogue", selfHostedOnly: true },
+ { id: "evolution", label: "Evolution", selfHostedOnly: true },
+ { id: "restore", label: "Restore & colourise", ownerOnly: true, selfHostedOnly: true },
{ id: "relight", label: "Relight" },
{ id: "depth", label: "Depth map" },
{ id: "captions", label: "Captions" },
@@ -53,3 +63,17 @@ export function modeHref(kind: HubKind, mode: string, query?: Record<string, str
const q = query ? new URLSearchParams(query).toString() : "";
return q ? `${path}?${q}` : path;
}
+
+/** The hub a path belongs to (/audio, /audio/music…), if any. */
+export function hubOfPath(pathname: string): HubKind | undefined {
+ const first = pathname.split(/[?#]/)[0].split("/")[1];
+ return (Object.keys(HUB_MODES) as HubKind[]).find((k) => k === first);
+}
+
+/** The mode a hub path shows: /audio is the first mode, /audio/music is Music. Undefined outside the hub or for an unknown mode. */
+export function modeOfPath(kind: HubKind, pathname: string): string | undefined {
+ const parts = pathname.split(/[?#]/)[0].split("/").filter(Boolean);
+ if (parts[0] !== kind || parts.length > 2) return undefined;
+ const id = parts[1] ?? HUB_MODES[kind][0].id;
+ return HUB_MODES[kind].some((m) => m.id === id) ? id : undefined;
+}
diff --git a/src/lib/use-tapped-tab.ts b/src/lib/use-tapped-tab.ts
new file mode 100644
index 00000000..ca622ef0
--- /dev/null
+++ b/src/lib/use-tapped-tab.ts
@@ -0,0 +1,22 @@
+"use client";
+
+import { useCallback, useLayoutEffect, useState } from "react";
+
+/**
+ * The tab just tapped in a bar of route tabs, to show as the current one in the very next frame, before the new route
+ * commits. It lasts while the address is the one it was tapped on: once the route moves the address says which tab is
+ * current. It is also dropped when the page is hidden (a page kept for Back), so going back shows that page's own tab.
+ */
+export function useTappedTab<T>(pathname: string | null): [T | null, (tab: T) => void] {
+ const [tapped, setTapped] = useState<{ at: string | null; tab: T } | null>(null);
+ // The route moved (or Back / Forward): the address says now.
+ if (tapped && tapped.at !== pathname) setTapped(null);
+ useLayoutEffect(() => () => setTapped(null), []);
+ const tap = useCallback((tab: T) => setTapped({ at: pathname, tab }), [pathname]);
+ return [tapped && tapped.at === pathname ? tapped.tab : null, tap];
+}
+
+/** A plain left click that navigates this tab (a modifier or another button opens a new tab or window instead). */
+export function isPlainClick(e: React.MouseEvent): boolean {
+ return !e.defaultPrevented && e.button === 0 && !e.metaKey && !e.ctrlKey && !e.shiftKey && !e.altKey;
+}
diff --git a/src/lib/when-idle.ts b/src/lib/when-idle.ts
new file mode 100644
index 00000000..f1df5049
--- /dev/null
+++ b/src/lib/when-idle.ts
@@ -0,0 +1,45 @@
+"use client";
+
+import { useSyncExternalStore } from "react";
+
+/** Runs `fn` once the browser is idle after the page has loaded (soon after, where requestIdleCallback is missing). Returns a cancel. */
+export function whenIdle(fn: () => void): () => void {
+ let idle = 0;
+ let timer = 0;
+ const schedule = () => {
+ if (typeof window.requestIdleCallback === "function") idle = window.requestIdleCallback(fn, { timeout: 2000 });
+ else timer = window.setTimeout(fn, 300);
+ };
+ if (document.readyState === "complete") schedule();
+ else window.addEventListener("load", schedule, { once: true });
+ return () => {
+ window.removeEventListener("load", schedule);
+ if (idle) window.cancelIdleCallback(idle);
+ if (timer) window.clearTimeout(timer);
+ };
+}
+
+let settled = false;
+let started = false;
+const listeners = new Set<() => void>();
+
+function subscribe(cb: () => void): () => void {
+ listeners.add(cb);
+ if (!started) {
+ started = true;
+ whenIdle(() => {
+ settled = true;
+ for (const l of listeners) l();
+ });
+ }
+ return () => listeners.delete(cb);
+}
+
+/** True once the page has loaded and the browser has had an idle moment (false on the server and while hydrating). */
+export function useSettled(): boolean {
+ return useSyncExternalStore(
+ subscribe,
+ () => settled,
+ () => false,
+ );
+}
diff --git a/tests/public-signup-tools.test.ts b/tests/public-signup-tools.test.ts
index 8cae9d80..c9fd4c94 100644
--- a/tests/public-signup-tools.test.ts
+++ b/tests/public-signup-tools.test.ts
@@ -299,7 +299,7 @@ describe("Split soundtrack's and Remove dialogue's pages tell a visitor up front
expect(page).toContain(`const SELF_HOSTED = "${tool} isn't available here";`);
expect(page).toMatch(/blocker = visitor \? SELF_HOSTED/);
expect(page).toMatch(/\{visitor && (\( ?)?<SelfHostNote className="mt-3 max-w-xl">\{SELF_HOSTED\}\.<\/SelfHostNote> ?\)?\}/);
- expect(page).toMatch(/<ToolShell title="[^"]+" tabs=\{tabs\} selfHostedOnly>/);
+ expect(page).toMatch(/<ToolShell title="[^"]+" selfHostedOnly>/);
expect(page).toMatch(/onUpdate=\{setSource\} disabled=\{visitor\}/);
// The upload button, From library, the hidden file input and the drop all honour it.
expect(page.match(/disabled=\{disabled\}/g)?.length).toBe(3);