Skip to content

Open source CapCut alternative.

TypeScript

feat(site): stage the starter project's first open

David Lee5161af037ee
diff --git a/site/public/cut-starter/project.json b/site/public/cut-starter/project.json
index 20650924..e989f799 100644
--- a/site/public/cut-starter/project.json
+++ b/site/public/cut-starter/project.json
@@ -207,7 +207,8 @@
"in": 0,
"out": 14.3,
"volume": 0.4,
- "lane": 1
+ "lane": 1,
+ "hidden": true
}
],
"overlays": [],
diff --git a/site/src/cut/components/AiPanel.tsx b/site/src/cut/components/AiPanel.tsx
index df6075d8..5cba2e84 100644
--- a/site/src/cut/components/AiPanel.tsx
+++ b/site/src/cut/components/AiPanel.tsx
@@ -258,6 +258,12 @@ export function AiPanel({
? crypto.randomUUID()
: (readActiveChat(projectId) ?? crypto.randomUUID()),
);
+ // Whether this browser held a chat pointer for the project before the write
+ // below stamps one; captured at mount so the resume in the merge effect can
+ // still tell a first open apart.
+ const [hadStoredChat] = useState(
+ () => typeof window !== "undefined" && readActiveChat(projectId) !== null,
+ );
useEffect(() => {
writeActiveChat(projectId, activeChat);
}, [activeChat, projectId]);
@@ -269,12 +275,23 @@ export function AiPanel({
useEffect(() => {
let alive = true;
void ensureCloudThreads(projectId).then(() => {
- if (alive) setChatsReady(true);
+ if (!alive) return;
+ // First open on this browser: resume the project's newest saved thread
+ // instead of a blank chat — for a new account's starter project that is
+ // the seeded walkthrough. Set before chatsReady so the session mounts
+ // once, on the right thread.
+ if (!hadStoredChat) {
+ setActiveChat((cur) => {
+ const list = readThreads(projectId);
+ return list.length > 0 && !list.some((t) => t.id === cur) ? list[0].id : cur;
+ });
+ }
+ setChatsReady(true);
});
return () => {
alive = false;
};
- }, [projectId]);
+ }, [projectId, hadStoredChat]);
// A shared view opens on the owner's newest thread — the viewer has no chat
// of their own to resume. Derived, so the fallback holds until the viewer
diff --git a/site/src/cut/components/Editor.tsx b/site/src/cut/components/Editor.tsx
index 4541d6dd..d9243dca 100644
--- a/site/src/cut/components/Editor.tsx
+++ b/site/src/cut/components/Editor.tsx
@@ -27,7 +27,10 @@ import { enrichAsset, importFileToProject, prepareImport } from "@/cut/lib/media
import "@/cut/lib/genScene";
import { installDevHooks } from "@/cut/lib/devHooks";
import { backTarget, useCutBase } from "@/cut/lib/nav";
+import { useOnboardingCover } from "@/cut/lib/onboarding";
+import { requestSidePanel } from "@/cut/lib/panelRequest";
import { resolveProjectPlacement } from "@/cut/lib/residency";
+import { starterProjectId } from "@/cut/lib/starter";
import {
docAudioClips,
docClips,
@@ -37,6 +40,7 @@ import {
useEditor,
} from "@/cut/lib/store";
import type { MediaAsset } from "@/cut/lib/types";
+import { authClient } from "@/lib/auth-client";
import { AiPanel } from "./AiPanel";
import { ExportDialog } from "./ExportDialog";
import { Inspector } from "./Inspector";
@@ -167,6 +171,32 @@ export function Editor({
};
}, [projectId, viewer]);
+ // The starter project's first open presents the finished cut: the side
+ // panel folds to its rail, chat opens on the seeded thread, and the video
+ // plays — held while the welcome slides still cover the editor, so it
+ // starts the moment they hand over. Once per browser; after this the
+ // layout is the user's own to keep.
+ const { data: session } = authClient.useSession();
+ const userId = session?.user.id;
+ useEffect(() => {
+ if (!loaded || viewer || !userId || projectId !== starterProjectId(userId)) return;
+ const seenKey = `cut-starter-intro-${projectId}`;
+ if (localStorage.getItem(seenKey)) return;
+ localStorage.setItem(seenKey, "1");
+ requestSidePanel(null);
+ useEditor.getState().setAiOpen(true);
+ if (!useOnboardingCover.getState().up) {
+ useEditor.getState().setPlaying(true);
+ return;
+ }
+ const unsub = useOnboardingCover.subscribe((s) => {
+ if (s.up) return;
+ unsub();
+ useEditor.getState().setPlaying(true);
+ });
+ return unsub;
+ }, [loaded, viewer, userId, projectId]);
+
// Delayed follow of the owner's edits: poll the doc version and reload on
// change, keeping the playhead. A 401/403/404 means the share was revoked or
// narrowed — stop and say so.
diff --git a/site/src/cut/components/onboarding/CutOnboarding.tsx b/site/src/cut/components/onboarding/CutOnboarding.tsx
index 4339b1cb..2e54699e 100644
--- a/site/src/cut/components/onboarding/CutOnboarding.tsx
+++ b/site/src/cut/components/onboarding/CutOnboarding.tsx
@@ -11,7 +11,7 @@ import { PlansSlide } from "@/cut/components/onboarding/slides/Plans";
import { ReferralSlide } from "@/cut/components/onboarding/slides/Referral";
import { WelcomeSlide } from "@/cut/components/onboarding/slides/Welcome";
import { useCutBase } from "@/cut/lib/nav";
-import { onOpenOnboarding } from "@/cut/lib/onboarding";
+import { onOpenOnboarding, setOnboardingCover } from "@/cut/lib/onboarding";
import { track } from "@/lib/analytics";
import { authClient } from "@/lib/auth-client";
import {
@@ -116,6 +116,12 @@ export function CutOnboarding() {
track("onboarding_started", { source: run });
}, [run]);
+ // The editor underneath reads this to hold the starter project's first
+ // playback until the slides hand over.
+ useEffect(() => {
+ setOnboardingCover(run !== null);
+ }, [run]);
+
// While the sequence is up, the address says so — it can be linked, reloaded,
// and read off the bar wherever it was opened from. This rewrites the address
// rather than navigating: the page underneath is already the right one, and
diff --git a/site/src/cut/lib/onboarding.ts b/site/src/cut/lib/onboarding.ts
index 98ec841e..2a8c72b2 100644
--- a/site/src/cut/lib/onboarding.ts
+++ b/site/src/cut/lib/onboarding.ts
@@ -2,8 +2,17 @@
// and the overlay mounted in the app shell that shows it. The overlay is
// mounted once, high in the tree; anything that wants it opens it from here.
+import { create } from "zustand";
+
const EVENT = "cut-onboarding-open";
+/** Whether the welcome sequence is covering the window right now. The starter
+ * project's first open waits on this before starting playback, so its music
+ * bed never plays under the slides. */
+export const useOnboardingCover = create<{ up: boolean }>(() => ({ up: false }));
+
+export const setOnboardingCover = (up: boolean) => useOnboardingCover.setState({ up });
+
export function openOnboarding(): void {
window.dispatchEvent(new Event(EVENT));
}