Skip to content

Open source CapCut alternative.

TypeScript

feat(site): one picker decides where projects and media land

David Le955e08fea6df
diff --git a/docs/guides/cut/README.md b/docs/guides/cut/README.md
index efae5c52..31358ea5 100644
--- a/docs/guides/cut/README.md
+++ b/docs/guides/cut/README.md
@@ -30,7 +30,7 @@ The client probes the engine's health endpoint (dedicated port first, dev server
Cloud projects make Cut usable in any browser on any OS with nothing installed, and they run alongside local ones: every account has both halves, and which one a project uses is decided per project.
-Every client call goes through a backend seam (`site/src/cut/lib/backend/`): the local driver is the engine transport unchanged, and the cloud driver rewrites the same paths to `/api/cut-cloud/*` with the session cookie. Residency is per project and fixed when the project is created, so creating one is where the user chooses: New project carries a picker — this Mac or the cloud — whenever both are reachable, and the choice sticks on that browser until they change it. With no Donkey app running there is nothing to choose and every new project is a cloud project; inside a folder the folder decides, since a project files only into a folder beside it. The home lists both shelves as one listing, each project badged with where it lives, and opening one binds the editor to that project's backend. Capability flags on the driver hide what a backend can't do, so components never feature-detect.
+Every client call goes through a backend seam (`site/src/cut/lib/backend/`): the local driver is the engine transport unchanged, and the cloud driver rewrites the same paths to `/api/cut-cloud/*` with the session cookie. Residency is per project and fixed when the project is created, so creating one is where the user chooses. One picker makes that choice, standing beside New project in the sidebar: it names a shelf — this Mac or the cloud — and everything the browser creates lands there, new projects and anything added to the library alike. The choice sticks on that browser until they change it, and every other New project button follows it rather than asking again. With no Donkey app running there is nothing to choose and every new project is a cloud project; inside a folder the folder decides, since a project files only into a folder beside it. The home lists both shelves as one listing, each project badged with where it lives, and opening one binds the editor to that project's backend. Capability flags on the driver hide what a backend can't do, so components never feature-detect.
The library is the exception, because it is a shelf rather than a place: it lists every residency the browser can reach at once — the Mac's when an engine has answered, the cloud's always — as one listing, newest first, with a badge saying which shelf each item is on. So a cloud project can pull a clip off this Mac, and a local project can pull one out of the cloud. Each item's own shelf answers for it: previews, renames, and deletes go to the backend it came from, and folders belong to one shelf, so items file only into folders beside them. Adding to a project is the one crossing: on the project's own shelf the server copies the file without the bytes leaving it, and off it the browser carries them down and back up.
diff --git a/site/src/cut/components/AppSidebar.tsx b/site/src/cut/components/AppSidebar.tsx
index 8cf27372..f1a1c084 100644
--- a/site/src/cut/components/AppSidebar.tsx
+++ b/site/src/cut/components/AppSidebar.tsx
@@ -82,7 +82,9 @@ export function AppSidebar() {
<span className="text-[17px] font-semibold tracking-tight">Donkey Cut</span>
</div>
+ {/* The one place the shelf is chosen: everything else follows it. */}
<NewProjectButton
+ picker
className="mb-5 w-full"
onCreate={(r) => {
setName("");
diff --git a/site/src/cut/components/LibraryView.tsx b/site/src/cut/components/LibraryView.tsx
index fd2caabd..24bfd6e3 100644
--- a/site/src/cut/components/LibraryView.tsx
+++ b/site/src/cut/components/LibraryView.tsx
@@ -52,12 +52,8 @@ import {
type LibraryAsset,
type LibraryData,
} from "@/cut/lib/library";
-import {
- activeResidency,
- availableResidencies,
- RESIDENCY_LABEL,
- type Residency,
-} from "@/cut/lib/residency";
+import { useNewProjectTarget } from "@/cut/lib/newProject";
+import { availableResidencies, RESIDENCY_LABEL, type Residency } from "@/cut/lib/residency";
import { TemplateCard } from "./TemplateCard";
import { homeHref, useCutBase } from "@/cut/lib/nav";
import { useRevealFlash } from "@/cut/lib/refReveal";
@@ -95,6 +91,10 @@ export function LibraryView() {
// The listing is cached (lib/queries.ts): coming back to the library paints
// the shelf it painted last time and revalidates behind it.
const library = useLibrary();
+ // New projects and new library items answer the same question — which shelf
+ // is this browser putting things on — so they read the one choice the user
+ // already made, rather than the backend the app happens to be bound to.
+ const { target } = useNewProjectTarget();
const all = library.data?.assets ?? [];
const folders = library.data?.folders ?? [];
const templates = library.data?.templates ?? [];
@@ -127,7 +127,7 @@ export function LibraryView() {
templates.find((t) => t.id === id)?.residency ??
null;
const shelfForNew = (folderId: string | null) =>
- (folderId ? folders.find((f) => f.id === folderId)?.residency : null) ?? activeResidency();
+ (folderId ? folders.find((f) => f.id === folderId)?.residency : null) ?? target;
const renameTpl = async (r: Residency, id: string, name: string) => {
patch((d) => ({ ...d, templates: d.templates.map((t) => (t.id === id ? { ...t, name } : t)) }));
@@ -344,7 +344,7 @@ export function LibraryView() {
}}
onOpen={gotoFolder}
onCreate={async (name) => {
- const f = await createLibraryFolder(name, activeResidency());
+ const f = await createLibraryFolder(name, target);
patch((d) => ({ ...d, folders: [...d.folders, f] }));
}}
onRename={async (id, name) => {
diff --git a/site/src/cut/components/NewProjectButton.tsx b/site/src/cut/components/NewProjectButton.tsx
index c27bdccf..3e1d0f8a 100644
--- a/site/src/cut/components/NewProjectButton.tsx
+++ b/site/src/cut/components/NewProjectButton.tsx
@@ -9,26 +9,47 @@ import {
DropdownMenuRadioItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger,
+} from "@/components/ui/tooltip";
import { useNewProjectTarget } from "@/cut/lib/newProject";
import { RESIDENCY_LABEL, type Residency } from "@/cut/lib/residency";
import { cn } from "@/lib/utils";
const RESIDENCY_ICON: Record<Residency, typeof Cloud> = { local: Laptop, cloud: Cloud };
+// The picker is one switch for the whole app, and its tooltip is where that
+// scope is stated: everything that lands on the shelf, then the shelf itself in
+// bold. The break is written into the copy rather than left to a width, so the
+// sentence reads the same in both shelves. The menu needs no more than the two
+// names.
+const RESIDENCY_LEAD = "All projects and media will";
+const RESIDENCY_SCOPE: Record<Residency, { tail: string; place: string }> = {
+ local: { tail: "be stored on", place: "this Mac" },
+ cloud: { tail: "be stored on the", place: "Cloud" },
+};
+
/**
- * Make a project, and say where it will land.
+ * Make a project, and — where the app keeps the switch — say where things land.
*
- * The chevron is the residency choice, and it appears only when there is one
+ * The chevron is that switch, and it appears once, in the sidebar: it sets the
+ * shelf for everything this browser creates, so every other New project button
+ * follows it rather than asking again. It appears only when there is a choice
* to make. Without the Donkey app running this Mac has no shelf, so every
- * project is a cloud project and this is a plain button. A folder pins its own
- * residency, since a project files only into a folder beside it.
+ * project is a cloud project. A folder pins its own residency, since a project
+ * files only into a folder beside it.
*/
export function NewProjectButton({
pinned = null,
+ picker = false,
onCreate,
className,
}: {
pinned?: Residency | null;
+ picker?: boolean;
onCreate: (r: Residency) => void;
className?: string;
}) {
@@ -36,7 +57,7 @@ export function NewProjectButton({
const r = pinned ?? target;
const Icon = RESIDENCY_ICON[r];
- if (pinned || choices.length < 2) {
+ if (!picker || pinned || choices.length < 2) {
return (
<Button className={className} onClick={() => onCreate(r)}>
<Plus data-icon="inline-start" /> New project
@@ -45,28 +66,40 @@ export function NewProjectButton({
}
return (
- <div className={cn("flex", className)}>
- {/* The two halves read as one control: no seam between them. The base
- button's transparent border sits over the page with bg-clip-padding,
- so the facing borders have to go or they show as a line. */}
- <Button
- className="min-w-0 flex-1 rounded-r-none border-r-0"
- onClick={() => onCreate(r)}
- >
+ <div className={cn("flex items-center gap-1.5", className)}>
+ {/* Two controls, not two halves of one: making a project and choosing the
+ shelf are separate acts, so they stand apart rather than sharing an
+ edge. */}
+ <Button className="min-w-0 flex-1" onClick={() => onCreate(r)}>
<Plus data-icon="inline-start" /> New project
</Button>
<DropdownMenu>
- <DropdownMenuTrigger
- render={
- <Button
- aria-label={`New projects go to ${RESIDENCY_LABEL[r]}`}
- className="gap-1 rounded-l-none border-l-0 pr-2 pl-1.5"
+ <TooltipProvider>
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <DropdownMenuTrigger
+ render={
+ <Button
+ aria-label={`Where new projects and media are saved: ${RESIDENCY_LABEL[r]}`}
+ className="shrink-0 gap-1 px-2"
+ />
+ }
+ >
+ <Icon className="size-3.5" />
+ <ChevronDown className="size-3" />
+ </DropdownMenuTrigger>
+ }
/>
- }
- >
- <Icon className="size-3.5" />
- <ChevronDown className="size-3" />
- </DropdownMenuTrigger>
+ <TooltipContent className="flex-col items-start gap-0 py-2 text-left">
+ <span>{RESIDENCY_LEAD}</span>
+ <span>
+ {RESIDENCY_SCOPE[r].tail}{" "}
+ <span className="font-semibold">{RESIDENCY_SCOPE[r].place}</span>
+ </span>
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
<DropdownMenuContent align="end">
<DropdownMenuRadioGroup value={r} onValueChange={(v) => pick(v as Residency)}>
{choices.map((c) => {
diff --git a/site/src/cut/components/ProjectsHome.tsx b/site/src/cut/components/ProjectsHome.tsx
index e3178d66..a96c42ba 100644
--- a/site/src/cut/components/ProjectsHome.tsx
+++ b/site/src/cut/components/ProjectsHome.tsx
@@ -87,7 +87,6 @@ type View = "gallery" | "list";
// directly — the global mode is only bound when a project opens into the
// editor. Each section's listing is cached (lib/queries.ts), so returning here
// paints the shelf immediately and revalidates behind it.
-const RESIDENCY_LABEL: Record<Residency, string> = { local: "On this Mac", cloud: "Cloud" };
type SectionData = {
projects: ProjectSummary[] | null;
@@ -538,7 +537,7 @@ export function ProjectsHome() {
folders={mergedFolders}
mime={PROJECT_MIME}
creating={folderCreating !== null}
- onCreatingChange={(c) => setFolderCreating(c ? (folderCreating ?? homeMode) : null)}
+ onCreatingChange={(c) => setFolderCreating(c ? (folderCreating ?? target) : null)}
statOf={(id) => {
const items = (data[residencyOfFolder(id)].projects ?? []).filter(
(p) => (p.folderId ?? null) === id
@@ -546,7 +545,7 @@ export function ProjectsHome() {
return { count: items.length, size: items.reduce((n, p) => n + (p.sizeBytes ?? 0), 0) };
}}
onOpen={gotoFolder}
- onCreate={(n) => void createFolder(folderCreating ?? homeMode, n)}
+ onCreate={(n) => void createFolder(folderCreating ?? target, n)}
onRename={(id, n) => void renameFolder(residencyOfFolder(id), id, n)}
onDelete={(id) => void deleteFolder(residencyOfFolder(id), id)}
onDropIds={(ids, fid) => void moveProjects(residencyOfFolder(fid), ids, fid)}
@@ -773,26 +772,13 @@ export function ProjectsHome() {
/>
)}
<div className="flex items-center gap-2">
- {openFolder === null &&
- (dual ? (
- <DropdownMenu>
- <DropdownMenuTrigger render={<Button variant="outline" />}>
- <FolderPlus data-icon="inline-start" /> New folder
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuItem onClick={() => setFolderCreating("local")}>
- <Laptop /> {RESIDENCY_LABEL.local}
- </DropdownMenuItem>
- <DropdownMenuItem onClick={() => setFolderCreating("cloud")}>
- <Cloud /> {RESIDENCY_LABEL.cloud}
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- ) : (
- <Button variant="outline" onClick={() => setFolderCreating(r0)}>
- <FolderPlus data-icon="inline-start" /> New folder
- </Button>
- ))}
+ {/* A folder lands where a project would: New project owns that
+ choice for the whole page, so this asks nothing of its own. */}
+ {openFolder === null && (
+ <Button variant="outline" onClick={() => setFolderCreating(target)}>
+ <FolderPlus data-icon="inline-start" /> New folder
+ </Button>
+ )}
<NewProjectButton
pinned={folderOwner}
onCreate={(r) => void newProjectHere(r)}