Open source CapCut alternative.
TypeScript
fix(chatgpt): keep the editor card off the projects home
David Le477e35417c03
diff --git a/site/src/cut/components/Editor.tsx b/site/src/cut/components/Editor.tsxindex fd5b75d9..6ca52277 100644--- a/site/src/cut/components/Editor.tsx+++ b/site/src/cut/components/Editor.tsx@@ -74,6 +74,7 @@ import { playheadAt, previewAt, skimAt } from "@/cut/lib/playhead";import type { MediaAsset } from "@/cut/lib/types";import { AiPanel } from "./AiPanel";import type { ChatStatus } from "./ChatStatusBadge";+import { EmbeddedNewProject } from "./EmbeddedNewProject";import { ExportDialog } from "./ExportDialog";import { Inspector, useHasInspector } from "./Inspector";import { Lightbox } from "./Lightbox";@@ -1198,6 +1199,19 @@ export function Editor({// Takes shot on a paired phone land in this project's media as they arrive.usePhoneInbox(importFiles);+ // The way out of a project that can't open. On the web it is the home tab+ // the project was opened from; the card has no home behind it, so a new+ // project opens in its place.+ const leave = chatgpt ? (+ <EmbeddedNewProject />+ ) : (+ <Button+ variant="outline"+ nativeButton={false}+ render={<Link href={back.href}>Back to {back.tab}</Link>}+ />+ );+// The project is here, on this Mac — it just can't be opened without the app// that holds it. The gate's banner sits above this with the recovery steps,// and the moment the app answers this screen loads the project itself.@@ -1210,11 +1224,7 @@ export function Editor({This is a local project — it lives on this Mac. Open the Donkey app and it openshere.</p>- <Button- variant="outline"- nativeButton={false}- render={<Link href={back.href}>Back to {back.tab}</Link>}- />+ {leave}</div></div>);@@ -1226,11 +1236,7 @@ export function Editor({<div className="flex flex-col items-center gap-3 text-center"><Clapperboard className="size-7 text-muted-foreground" /><p className="text-sm text-muted-foreground">{loadError}</p>- <Button- variant="outline"- nativeButton={false}- render={<Link href={back.href}>Back to {back.tab}</Link>}- />+ {leave}</div></div>);diff --git a/site/src/cut/components/EmbeddedNewProject.tsx b/site/src/cut/components/EmbeddedNewProject.tsxnew file mode 100644index 00000000..b1a123fd--- /dev/null+++ b/site/src/cut/components/EmbeddedNewProject.tsx@@ -0,0 +1,53 @@+"use client";++import { useState } from "react";+import { useRouter } from "next/navigation";++import { Button } from "@/components/ui/button";+import { cloudBackend } from "@/cut/lib/backend/cloud";+import { seedNewProjectDoc } from "@/cut/lib/docCache";+import { framedHref } from "@/cut/lib/hostBridge";+import { projectHref, useCutBase } from "@/cut/lib/nav";+import { lastChosenAspect } from "@/cut/lib/store";+import type { ProjectSummary } from "@/cut/lib/types";+import { track } from "@/lib/analytics";++// The card's way forward when the project it was opened on can't be shown.+// The card is the whole surface, so there is no projects home to go back to:+// a new cloud project is made and opened here in its place.+export function EmbeddedNewProject() {+ const router = useRouter();+ const base = useCutBase();+ const [busy, setBusy] = useState(false);+ const [error, setError] = useState<string | null>(null);++ const create = async () => {+ setBusy(true);+ setError(null);+ try {+ const aspect = lastChosenAspect() ?? undefined;+ const res = await cloudBackend.fetch("/api/cut/projects", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ name: "Untitled", folderId: null, aspect }),+ });+ if (!res.ok) throw new Error("Could not create the project.");+ const project = (await res.json()) as ProjectSummary;+ seedNewProjectDoc(project.id, project.name, "cloud", aspect);+ track("project_created", { source: "chatgpt_card" });+ router.replace(framedHref(projectHref(base, project.id, "projects")));+ } catch (e) {+ setError(e instanceof Error && e.message ? e.message : "Could not create the project.");+ setBusy(false);+ }+ };++ return (+ <>+ <Button variant="outline" disabled={busy} onClick={() => void create()}>+ Create New Project+ </Button>+ {error && <p className="text-xs text-destructive">{error}</p>}+ </>+ );+}diff --git a/site/src/cut/components/ExportsDock.tsx b/site/src/cut/components/ExportsDock.tsxindex 6393e9fb..9e83891b 100644--- a/site/src/cut/components/ExportsDock.tsx+++ b/site/src/cut/components/ExportsDock.tsx@@ -24,6 +24,7 @@ import {type ExportJob,type LocalRow,} from "@/cut/lib/exportStore";+import { framedHref } from "@/cut/lib/hostBridge";import { projectHref, useCutBase } from "@/cut/lib/nav";import { cn } from "@/lib/utils";@@ -130,7 +131,7 @@ function ProjectName({ projectId, name }: { projectId: string; name?: string })const base = useCutBase();return (<Link- href={projectHref(base, projectId, "projects")}+ href={framedHref(projectHref(base, projectId, "projects"))}className="block truncate text-xs font-medium hover:underline"title={name || "Untitled"}>diff --git a/site/src/cut/lib/hostBridge.ts b/site/src/cut/lib/hostBridge.tsindex 06d3ff13..37cd2676 100644--- a/site/src/cut/lib/hostBridge.ts+++ b/site/src/cut/lib/hostBridge.ts@@ -81,6 +81,13 @@ export function useHostReady(ready: boolean) {}, [ready]);}+/** An address the frame itself navigates to keeps the embed flag, so the page+ * it lands on is still the card. On the web the address is returned as is. */+export function framedHref(href: string): string {+ if (editorHost() !== "chatgpt") return href;+ return `${href}${href.includes("?") ? "&" : "?"}embed=chatgpt`;+}+/** The project on donkeycut.com: this page without the frame's embed flag. */export function projectPageUrl(): string {const url = new URL(window.location.href);diff --git a/site/src/lib/analytics.ts b/site/src/lib/analytics.tsindex 82bd7c86..9daa1755 100644--- a/site/src/lib/analytics.ts+++ b/site/src/lib/analytics.ts@@ -25,7 +25,7 @@ export type AnalyticsEvents = {};onboarding_completed: { source: OnboardingRun; skipped: boolean; step: number };// Cut projects home.- project_created: { source: "projects_home" | "sidebar" | "file_import" };+ project_created: { source: "projects_home" | "sidebar" | "file_import" | "chatgpt_card" };folder_created: void;// Cut cloud storage limits.cut_storage_pill_clicked: void;