Skip to content

The VS Code of video editing, built for agents.

TypeScript

feat: add collections management to dashboard

konstantin-paulus78fe83fbf8c0
diff --git a/apps/web/src/assets/icons/view-grid.svg b/apps/web/src/assets/icons/view-grid.svg
new file mode 100644
index 00000000..f408529f
--- /dev/null
+++ b/apps/web/src/assets/icons/view-grid.svg
@@ -0,0 +1,3 @@
+<svg viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M11.1025 13.0049C11.6067 13.0562 12 13.4823 12 14V17.5L11.9951 17.6025C11.9472 18.073 11.573 18.4472 11.1025 18.4951L11 18.5H7.5C6.9823 18.5 6.5562 18.1067 6.5049 17.6025L6.5 17.5V14C6.5 13.4477 6.9477 13 7.5 13H11L11.1025 13.0049ZM17.6025 13.0049C18.1067 13.0562 18.5 13.4823 18.5 14V17.5L18.4951 17.6025C18.4472 18.073 18.073 18.4472 17.6025 18.4951L17.5 18.5H14C13.4823 18.5 13.0562 18.1067 13.0049 17.6025L13 17.5V14C13 13.4477 13.4477 13 14 13H17.5L17.6025 13.0049ZM14 17.5H17.5V14H14V17.5ZM7.5 17.5H11V14H7.5V17.5ZM11.1025 6.5049C11.6067 6.5562 12 6.9823 12 7.5V11L11.9951 11.1025C11.9472 11.573 11.573 11.9472 11.1025 11.9951L11 12H7.5C6.9823 12 6.5562 11.6067 6.5049 11.1025L6.5 11V7.5C6.5 6.9477 6.9477 6.5 7.5 6.5H11L11.1025 6.5049ZM17.6025 6.5049C18.1067 6.5562 18.5 6.9823 18.5 7.5V11L18.4951 11.1025C18.4472 11.573 18.073 11.9472 17.6025 11.9951L17.5 12H14C13.4823 12 13.0562 11.6067 13.0049 11.1025L13 11V7.5C13 6.9477 13.4477 6.5 14 6.5H17.5L17.6025 6.5049ZM7.5 11H11V7.5H7.5V11ZM14 11H17.5V7.5H14V11Z" fill="currentColor"/>
+</svg>
diff --git a/apps/web/src/components/dashboard/collections-nav.tsx b/apps/web/src/components/dashboard/collections-nav.tsx
new file mode 100644
index 00000000..d2259516
--- /dev/null
+++ b/apps/web/src/components/dashboard/collections-nav.tsx
@@ -0,0 +1,203 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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 { For, Show, createSignal } from "solid-js";
+import { toast } from "somoto";
+
+import {
+ ContextMenu,
+ ContextMenuContent,
+ ContextMenuItem,
+ ContextMenuPortal,
+ ContextMenuTrigger,
+} from "@/components/ui/context-menu";
+import { Icon } from "@/components/ui/icon";
+import { TextField, TextFieldInput } from "@/components/ui/text-field";
+import {
+ createCollection,
+ deleteCollection,
+ renameCollection,
+ type CollectionRecord,
+} from "@/projects";
+
+import { DashboardSidebarItem } from "./sidebar";
+
+type DashboardSidebarCollectionsProps = {
+ collections: CollectionRecord[];
+ /** The collection the projects view lists, if it lists one. */
+ activeId: string | null;
+ onOpen(collection: CollectionRecord): void;
+};
+
+/**
+ * The collections in the sidebar, each opening the projects filed in it, and
+ * the row that adds one. A collection's menu renames it in place or deletes
+ * it; deleting one keeps its projects, at the top level.
+ */
+export function DashboardSidebarCollections(props: DashboardSidebarCollectionsProps) {
+ const [adding, setAdding] = createSignal(false);
+
+ // A folder just named is opened, ready to fill.
+ const handleAdd = async (name: string) => {
+ setAdding(false);
+ try {
+ const collection = await createCollection(name);
+ props.onOpen(collection);
+ } catch (e) {
+ toast.error("Failed to add folder", { description: (e as Error).message });
+ }
+ };
+
+ return (
+ <>
+ <For each={props.collections}>
+ {(collection) => (
+ <CollectionItem
+ collection={collection}
+ active={props.activeId === collection.id}
+ onOpen={() => props.onOpen(collection)}
+ />
+ )}
+ </For>
+ <Show
+ when={adding()}
+ fallback={<DashboardSidebarItem icon="plus-add" label="Add folder..." onClick={() => setAdding(true)} />}
+ >
+ <SidebarNameField
+ icon="navigation.folder"
+ value=""
+ placeholder="Folder name"
+ onCommit={handleAdd}
+ onCancel={() => setAdding(false)}
+ />
+ </Show>
+ </>
+ );
+}
+
+type CollectionItemProps = {
+ collection: CollectionRecord;
+ active: boolean;
+ onOpen(): void;
+};
+
+function CollectionItem(props: CollectionItemProps) {
+ const [renaming, setRenaming] = createSignal(false);
+
+ const handleRename = async (name: string) => {
+ setRenaming(false);
+ if (name === props.collection.name) return;
+ try {
+ await renameCollection(props.collection, name);
+ } catch (e) {
+ toast.error("Failed to rename folder", { description: (e as Error).message });
+ }
+ };
+
+ const handleDelete = async () => {
+ try {
+ await deleteCollection(props.collection.id);
+ } catch (e) {
+ toast.error("Failed to delete folder", { description: (e as Error).message });
+ }
+ };
+
+ return (
+ <Show
+ when={!renaming()}
+ fallback={
+ <SidebarNameField
+ icon="navigation.folder"
+ value={props.collection.name}
+ placeholder="Folder name"
+ onCommit={handleRename}
+ onCancel={() => setRenaming(false)}
+ />
+ }
+ >
+ <ContextMenu modal={false}>
+ <ContextMenuTrigger as="div" class="contents">
+ <DashboardSidebarItem
+ icon="navigation.folder"
+ label={props.collection.name}
+ active={props.active}
+ onClick={props.onOpen}
+ />
+ </ContextMenuTrigger>
+ <ContextMenuPortal>
+ <ContextMenuContent class="w-45 gap-0">
+ <ContextMenuItem onSelect={() => setRenaming(true)}>Rename</ContextMenuItem>
+ <ContextMenuItem onSelect={handleDelete}>Delete folder</ContextMenuItem>
+ </ContextMenuContent>
+ </ContextMenuPortal>
+ </ContextMenu>
+ </Show>
+ );
+}
+
+type SidebarNameFieldProps = {
+ icon: string;
+ value: string;
+ placeholder: string;
+ /** Enter, or focus leaving, with a name typed: the trimmed name. */
+ onCommit(name: string): void;
+ /** Escape, or focus leaving with nothing typed. */
+ onCancel(): void;
+};
+
+/** A sidebar row whose label is a field, for naming a collection in place. */
+function SidebarNameField(props: SidebarNameFieldProps) {
+ // Enter blurs the field on its way out; the blur must not answer again.
+ let settled = false;
+
+ const settle = (name: string | null) => {
+ if (settled) return;
+ settled = true;
+ if (name) props.onCommit(name);
+ else props.onCancel();
+ };
+
+ // A field mounted from a context-menu selection gets its focus taken back
+ // by the trigger as the menu closes, so it claims focus after that.
+ const handleRef = (el: HTMLInputElement) => {
+ queueMicrotask(() => {
+ el.focus();
+ el.select();
+ });
+ };
+
+ const handleKeyDown = (event: KeyboardEvent & { currentTarget: HTMLInputElement }) => {
+ if (event.key === "Escape") {
+ event.preventDefault();
+ event.stopPropagation();
+ settle(null);
+ }
+ if (event.key === "Enter") {
+ event.preventDefault();
+ event.stopPropagation();
+ settle(event.currentTarget.value.trim());
+ }
+ };
+
+ return (
+ <div class="my-0.5 flex h-7 w-full shrink-0 items-center gap-1 rounded-md pl-0 pr-1">
+ <span class="grid size-7 shrink-0 place-items-center overflow-clip">
+ <Icon name={props.icon} class="text-muted-foreground" />
+ </span>
+ <TextField class="min-w-0 flex-1">
+ <TextFieldInput
+ uiSize="compact"
+ type="text"
+ ref={handleRef}
+ value={props.value}
+ onKeyDown={handleKeyDown}
+ onBlur={(event) => settle(event.currentTarget.value.trim())}
+ placeholder={props.placeholder}
+ aria-label={props.placeholder}
+ class="h-5 w-full border border-ring bg-input px-1 py-0 ring-1 ring-inset ring-ring"
+ />
+ </TextField>
+ </div>
+ );
+}
diff --git a/apps/web/src/components/dashboard/home-view.tsx b/apps/web/src/components/dashboard/home-view.tsx
index d0739df7..f0796188 100644
--- a/apps/web/src/components/dashboard/home-view.tsx
+++ b/apps/web/src/components/dashboard/home-view.tsx
@@ -8,7 +8,6 @@ import {
Show,
createEffect,
createMemo,
- createResource,
createSignal,
onCleanup,
} from "solid-js";
@@ -47,9 +46,7 @@ import { track } from "@/lib/analytics";
import {
createProject,
isDesktop,
- listProjects,
projectKey,
- projectsRevision,
type ProjectInfo,
} from "@/projects";
@@ -62,6 +59,7 @@ import {
DashboardCardPreview,
createBackgroundClickHandler,
createNewProject,
+ createProjectList,
openProjectFromList,
} from "./shared";
import { parseTimestamp } from "./utils";
@@ -129,10 +127,7 @@ export function DashboardHomeView() {
// The projects the app knows — created here, or opened from a folder —
// refetched whenever that list changes.
- const [projects, { refetch: refetchProjects }] = createResource(
- projectsRevision,
- () => listProjects(),
- );
+ const [projects, { refetch: refetchProjects }] = createProjectList();
// The model is shared with the chat panel and remembered across sessions;
// the picker is fed by the agent host's probes, so what it offers is what
// is installed and signed in.
diff --git a/apps/web/src/components/dashboard/project-card.tsx b/apps/web/src/components/dashboard/project-card.tsx
index 08efb3d7..07524ca8 100644
--- a/apps/web/src/components/dashboard/project-card.tsx
+++ b/apps/web/src/components/dashboard/project-card.tsx
@@ -7,16 +7,27 @@ import { toast } from "somoto";
import {
ContextMenu,
+ ContextMenuCheckboxItem,
ContextMenuContent,
ContextMenuItem,
ContextMenuPortal,
ContextMenuSeparator,
+ ContextMenuSub,
+ ContextMenuSubContent,
+ ContextMenuSubTrigger,
ContextMenuTrigger,
} from "@/components/ui/context-menu";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
import { track } from "@/lib/analytics";
import { listEditors, openInEditor, revealPath, type EditorInfo } from "@/lib/shell";
-import { duplicateProject, isWindowsDesktop, renameProject, type ProjectRecord } from "@/projects";
+import {
+ duplicateProject,
+ isWindowsDesktop,
+ listCollections,
+ moveProjectsToCollection,
+ renameProject,
+ type ProjectRecord,
+} from "@/projects";
import { DashboardCardButton, DashboardCardPreview, DashboardProjectThumbnail } from "./shared";
import { formatEditedAt } from "./utils";
@@ -42,10 +53,10 @@ type DashboardProjectCardProps = {
/**
* A project in a dashboard grid: thumbnail, name, and last-edited time, with
* the context menu that opens it (here, in the file manager, or in a code
- * editor), renames, duplicates, and deletes it. Rename
- * happens inline, in place of the name, and lives here so every grid that
- * shows projects gets the same menu. With more than one project selected,
- * the menu only duplicates and deletes them all.
+ * editor), renames, duplicates, files it in a collection, and deletes it.
+ * Rename happens inline, in place of the name, and lives here so every grid
+ * that shows projects gets the same menu. With more than one project
+ * selected, the menu only duplicates, files, and deletes them all.
*/
export function DashboardProjectCard(props: DashboardProjectCardProps) {
const [renaming, setRenaming] = createSignal(false);
@@ -203,6 +214,7 @@ export function DashboardProjectCard(props: DashboardProjectCardProps) {
fallback={
<>
<ContextMenuItem onSelect={handleDuplicate}>Duplicate {props.targets.length} projects</ContextMenuItem>
+ <MoveToMenu projects={props.targets} />
<ContextMenuSeparator class="my-2" />
<ContextMenuItem onSelect={props.onDelete}>Delete {props.targets.length} projects</ContextMenuItem>
</>
@@ -221,6 +233,7 @@ export function DashboardProjectCard(props: DashboardProjectCardProps) {
<ContextMenuSeparator class="my-2" />
<ContextMenuItem onSelect={startRenaming}>Rename</ContextMenuItem>
<ContextMenuItem onSelect={handleDuplicate}>Duplicate</ContextMenuItem>
+ <MoveToMenu projects={props.targets} />
<ContextMenuSeparator class="my-2" />
<ContextMenuItem onSelect={props.onDelete}>Delete</ContextMenuItem>
</Show>
@@ -229,3 +242,46 @@ export function DashboardProjectCard(props: DashboardProjectCardProps) {
</ContextMenu>
);
}
+
+/**
+ * Move to ▸ every collection, checked for the one `projects` are filed in. A
+ * project is in one collection at most: checking another moves it there, and
+ * unchecking the checked one takes it back to the top level. Mounts with the
+ * menu, so the collections are read when it opens.
+ */
+function MoveToMenu(props: { projects: ProjectRecord[] }) {
+ const [collections] = createResource(listCollections, { initialValue: [] });
+ // Checked only when every project is in it, so a mixed selection checks none.
+ const isIn = (id: string) => props.projects.every((project) => project.collectionId === id);
+
+ const move = async (collectionId: string | undefined) => {
+ try {
+ await moveProjectsToCollection(props.projects.map((project) => project.dir), collectionId);
+ } catch (e) {
+ toast.error("Failed to move project", { description: (e as Error).message });
+ }
+ };
+
+ return (
+ <ContextMenuSub>
+ <ContextMenuSubTrigger>Move to</ContextMenuSubTrigger>
+ <ContextMenuPortal>
+ <ContextMenuSubContent class="w-45 gap-0">
+ <For
+ each={collections()}
+ fallback={<ContextMenuItem disabled>No folders</ContextMenuItem>}
+ >
+ {(collection) => (
+ <ContextMenuCheckboxItem
+ checked={isIn(collection.id)}
+ onChange={(checked) => move(checked ? collection.id : undefined)}
+ >
+ <span class="min-w-0 flex-1 truncate">{collection.name}</span>
+ </ContextMenuCheckboxItem>
+ )}
+ </For>
+ </ContextMenuSubContent>
+ </ContextMenuPortal>
+ </ContextMenuSub>
+ );
+}
diff --git a/apps/web/src/components/dashboard/projects-view.tsx b/apps/web/src/components/dashboard/projects-view.tsx
index c6ec42eb..d67bffbe 100644
--- a/apps/web/src/components/dashboard/projects-view.tsx
+++ b/apps/web/src/components/dashboard/projects-view.tsx
@@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { toast } from "somoto";
-import { For, createMemo, createResource, createSignal } from "solid-js";
+import { For, createMemo, createSignal } from "solid-js";
import { useNavigate } from "@solidjs/router";
import {
@@ -20,6 +20,7 @@ import {
DashboardCardPreview,
DashboardViewSection,
createNewProject,
+ createProjectList,
openProjectFromList,
} from "./shared";
import { DeleteProjectDialog } from "./delete-project-dialog";
@@ -30,21 +31,30 @@ import { DashboardSearchPanel } from "./search-bar";
import { projectRoute, useReturnHere } from "@/hooks/use-project-route";
import { Icon } from "../ui/icon";
import { track } from "@/lib/analytics";
-import {
- listProjects,
- projectKey,
- projectsRevision,
- type ProjectInfo,
-} from "@/projects";
+import { projectKey, type ProjectInfo } from "@/projects";
+
+import type { ProjectScope, ProjectSortOption } from "./types";
+
+type DashboardProjectsViewProps = {
+ scope: ProjectScope;
+};
-import type { ProjectSortOption } from "./types";
+const scopeTitle = (scope: ProjectScope): string => {
+ if (scope.kind === "drafts") return "Drafts";
+ if (scope.kind === "collection") return scope.collection.name;
+ return "All projects";
+};
-export function DashboardProjectsView() {
+/** The id of the collection `scope` lists, if it lists one. */
+const scopeCollectionId = (scope: ProjectScope): string | undefined =>
+ scope.kind === "collection" ? scope.collection.id : undefined;
+
+export function DashboardProjectsView(props: DashboardProjectsViewProps) {
const navigate = useNavigate();
const returnHere = useReturnHere();
const [search, setSearch] = createSignal("");
const [sort, setSort] = createSignal<ProjectSortOption>("last-viewed");
- const [projects, { refetch: refetchProjects }] = createResource(projectsRevision, () => listProjects());
+ const [projects, { refetch: refetchProjects }] = createProjectList();
const [creating, setCreating] = createSignal(false);
const [pendingDelete, setPendingDelete] = createSignal<ProjectInfo[]>([]);
const [grid, setGrid] = createSignal<HTMLDivElement>();
@@ -54,9 +64,17 @@ export function DashboardProjectsView() {
const normalizedSearch = createMemo(() => search().trim().toLowerCase());
+ const scopedProjects = createMemo(() => {
+ const scope = props.scope;
+ const entries = projects() ?? [];
+ if (scope.kind === "drafts") return entries.filter((project) => project.draft);
+ if (scope.kind === "collection") return entries.filter((project) => project.collectionId === scope.collection.id);
+ return entries;
+ });
+
const filteredProjects = createMemo(() => {
const query = normalizedSearch();
- const entries = projects() ?? [];
+ const entries = scopedProjects();
if (!query) return entries;
return entries.filter((project) => project.displayName.toLowerCase().includes(query));
@@ -106,7 +124,7 @@ export function DashboardProjectsView() {
setCreating(true);
try {
- const project = await createNewProject();
+ const project = await createNewProject(scopeCollectionId(props.scope));
if (!project) return;
refetchProjects();
openProject(project);
@@ -121,11 +139,11 @@ export function DashboardProjectsView() {
<DashboardSearchPanel
value={search}
onChange={setSearch}
- placeholder="Search in projects"
+ placeholder={props.scope.kind === "all" ? "Search in projects" : `Search in ${scopeTitle(props.scope)}`}
>
<DashboardViewSection
class="pb-4"
- title="Recent projects"
+ title={scopeTitle(props.scope)}
onBackgroundClick={selection.clear}
gridRef={setGrid}
controls={
diff --git a/apps/web/src/components/dashboard/shared.tsx b/apps/web/src/components/dashboard/shared.tsx
index b1154122..2598575e 100644
--- a/apps/web/src/components/dashboard/shared.tsx
+++ b/apps/web/src/components/dashboard/shared.tsx
@@ -18,6 +18,7 @@ import {
onCleanup,
type JSX,
} from "solid-js";
+import { createStore, reconcile } from "solid-js/store";
import { Separator } from "../ui/separator";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { toast } from "somoto";
@@ -30,7 +31,9 @@ import {
deleteProject,
forgetProject,
isDesktop,
+ listProjects,
locateProject,
+ projectsRevision,
relocateProject,
type ProjectInfo,
} from "@/projects";
@@ -548,16 +551,40 @@ export function createBackgroundClickHandler(onCLick: () => void): JSX.EventHand
}
/**
- * Creates a fresh project — an "Untitled" draft — and puts it on the list.
- * Null, with the reason already shown, when there is no desktop to create it
- * on. The one flow behind every "new project": the card on each view.
+ * The projects the app knows, refetched whenever that list changes. Each
+ * refetch is merged into the last by folder, so a project that is still there
+ * keeps its object and only its changed fields update: the card showing it
+ * stays mounted, and a menu open on it stays open (a move to a collection
+ * checks its new one in place).
*/
-export async function createNewProject(): Promise<ProjectInfo | null> {
+export function createProjectList() {
+ return createResource(projectsRevision, () => listProjects(), {
+ storage: (initial) => {
+ const [store, setStore] = createStore({ value: initial });
+ return [
+ () => store.value,
+ (next) => {
+ const value = typeof next === "function" ? next(store.value) : next;
+ setStore("value", reconcile(value, { key: "dir" }));
+ return store.value;
+ },
+ ];
+ },
+ });
+}
+
+/**
+ * Creates a fresh project — an "Untitled" draft — and puts it on the list,
+ * filed in `collectionId` when one is given. Null, with the reason already
+ * shown, when there is no desktop to create it on. The one flow behind every
+ * "new project": the card on each view.
+ */
+export async function createNewProject(collectionId?: string): Promise<ProjectInfo | null> {
if (!isDesktop()) {
toast.error("Projects on disk are only available in the desktop app");
return null;
}
- const project = await createProject();
+ const project = await createProject(collectionId);
track("project_created");
return project;
}
diff --git a/apps/web/src/components/dashboard/sidebar.tsx b/apps/web/src/components/dashboard/sidebar.tsx
index 0eddd673..4c234cdf 100644
--- a/apps/web/src/components/dashboard/sidebar.tsx
+++ b/apps/web/src/components/dashboard/sidebar.tsx
@@ -98,7 +98,7 @@ type DashboardSidebarNavProps = {
/** The scrolling middle of the sidebar: stacked sections, then empty space. */
export function DashboardSidebarNav(props: DashboardSidebarNavProps) {
return (
- <div class="flex min-h-0 flex-1 flex-col gap-2 px-3">
+ <div class="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-3">
{props.children}
<div class="min-h-0 flex-1" />
{props.footer}
@@ -141,7 +141,7 @@ export function DashboardSidebarSection(props: DashboardSidebarSectionProps) {
<div class="flex shrink-0 flex-col">
<Show when={props.title}>
<div class="flex h-8 shrink-0 items-center px-1">
- <p class="text-xs text-muted-foreground">{props.title}</p>
+ <p class="text-xs font-450 text-muted-foreground">{props.title}</p>
</div>
</Show>
{props.children}
diff --git a/apps/web/src/components/dashboard/types.ts b/apps/web/src/components/dashboard/types.ts
index 0a55e26e..82cba68e 100644
--- a/apps/web/src/components/dashboard/types.ts
+++ b/apps/web/src/components/dashboard/types.ts
@@ -2,7 +2,14 @@
* 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/. */
-export type DashboardView = "home" | "projects" | "templates" | "ai-credits" | "billing" | "account" | "settings" | "mcp" | "preferences" | "help";
+import type { CollectionRecord } from "@/projects";
+
+export type DashboardView = "home" | "projects" | "drafts" | "templates" | "ai-credits" | "billing" | "account" | "settings" | "mcp" | "preferences" | "help";
+/** Which projects the projects view lists: all of them, the drafts, or one collection's. */
+export type ProjectScope =
+ | { kind: "all" }
+ | { kind: "drafts" }
+ | { kind: "collection"; collection: CollectionRecord };
export type ProjectSortOption = | "last-viewed" | "alphabetical" | "date-created";
export type TemplateSourceOption = "official" | "custom";
export type TemplatePreviewKind = "landscape" | "portrait" | "square";
diff --git a/apps/web/src/components/ui/context-menu.tsx b/apps/web/src/components/ui/context-menu.tsx
index b4dd00ee..3c155a9e 100644
--- a/apps/web/src/components/ui/context-menu.tsx
+++ b/apps/web/src/components/ui/context-menu.tsx
@@ -8,6 +8,7 @@ import type { Accessor, ComponentProps, ValidComponent } from "solid-js"
import { createContext, splitProps, useContext } from "solid-js"
import { ContextMenu as ContextMenuPrimitive } from "@kobalte/core/context-menu"
+import { Icon } from "@/components/ui/icon"
import { cx } from "@/lib/cva"
export const ContextMenuPortal = ContextMenuPrimitive.Portal
@@ -214,26 +215,14 @@ export const ContextMenuCheckboxItem = <T extends ValidComponent = "div">(
data-slot="context-menu-checkbox-item"
disabled={local.disabled || isContentDisabled()}
class={cx(
- "group data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
+ "group data-[highlighted]:bg-primary data-[highlighted]:text-primary-foreground relative flex cursor-default items-center gap-1 rounded-md bg-popover pr-2 pl-7 py-0 text-xs outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 h-7 w-full",
local.class,
)}
{...rest}
>
- <span class="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
- <ContextMenuPrimitive.ItemIndicator
- as="svg"
- xmlns="http://www.w3.org/2000/svg"
- class="size-4"
- viewBox="0 0 24 24"
- >
- <path
- fill="none"
- stroke="currentColor"
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M20 6L9 17l-5-5"
- />
+ <span class="pointer-events-none absolute left-0.5 flex size-6 items-center justify-center">
+ <ContextMenuPrimitive.ItemIndicator>
+ <Icon name="confirm-check" class="text-foreground group-data-[highlighted]:text-primary-foreground" />
</ContextMenuPrimitive.ItemIndicator>
</span>
{local.children}
diff --git a/apps/web/src/lib/db.ts b/apps/web/src/lib/db.ts
index 653f6a67..cf46ff82 100644
--- a/apps/web/src/lib/db.ts
+++ b/apps/web/src/lib/db.ts
@@ -16,6 +16,18 @@ export interface ProjectRecord extends ProjectInfo {
recordedAt: string; // When the app first put it on record.
lastOpenedAt: string;
cover: Blob | null;
+ collectionId?: string; // The collection it is filed in; none files it at the top level.
+}
+
+/**
+ * A collection of projects: a folder in the dashboard, not on disk. Projects
+ * name the one they are in (`ProjectRecord.collectionId`), so a collection
+ * can be empty, and renaming one is one write.
+ */
+export interface CollectionRecord {
+ id: string;
+ name: string;
+ createdAt: string;
}
/**
@@ -44,12 +56,16 @@ export interface GlobalDBSchema extends idb.DBSchema {
value: ProjectBundle;
key: string;
};
+ collections: {
+ value: CollectionRecord;
+ key: string;
+ };
}
type UpgradeTransaction = Parameters<NonNullable<idb.OpenDBCallbacks<GlobalDBSchema>['upgrade']>>[3];
const DB_NAME = 'diffusion-studio-idb';
-const DB_VERSION = 3;
+const DB_VERSION = 4;
const dbPromise = openDB<GlobalDBSchema>(DB_NAME, DB_VERSION, {
async upgrade(db, _oldVersion, _newVersion, tx) {
@@ -61,6 +77,9 @@ const dbPromise = openDB<GlobalDBSchema>(DB_NAME, DB_VERSION, {
store.createIndex('by-id', 'id');
store.createIndex('by-last-opened', 'lastOpenedAt');
}
+ if (!db.objectStoreNames.contains('collections')) {
+ db.createObjectStore('collections', { keyPath: 'id' });
+ }
if (db.objectStoreNames.contains('roots' as never)) await retireRoots(db, tx);
},
});
@@ -104,16 +123,17 @@ async function retireRoots(db: idb.IDBPDatabase<GlobalDBSchema>, tx: UpgradeTran
/**
* Puts `project` on record as just opened — what its folder says now,
- * replacing the copy the record held — or on record for the first time.
+ * replacing the copy the record held — or on record for the first time, filed
+ * in `collectionId` when one is given.
*/
-export async function rememberProject(project: ProjectInfo): Promise<ProjectRecord> {
+export async function rememberProject(project: ProjectInfo, collectionId?: string): Promise<ProjectRecord> {
const db = await dbPromise;
const now = new Date().toISOString();
const existing = await db.get('projects', project.dir);
const record: ProjectRecord = existing
? { ...existing, ...project, lastOpenedAt: now }
- : { ...project, recordedAt: now, lastOpenedAt: now, cover: null };
+ : { ...project, recordedAt: now, lastOpenedAt: now, cover: null, collectionId };
await db.put('projects', record);
return record;
@@ -132,6 +152,12 @@ export async function updateProjectRecord(project: ProjectInfo): Promise<void> {
await tx.done;
}
+/** The record for the project in `dir`, or undefined when it is not on record. */
+export async function getProjectRecord(dir: string): Promise<ProjectRecord | undefined> {
+ const db = await dbPromise;
+ return db.get('projects', dir);
+}
+
/** Every project on record, most recently opened first. */
export async function listProjectRecords(): Promise<ProjectRecord[]> {
const db = await dbPromise;
@@ -188,6 +214,51 @@ export async function forgetProject(dir: string): Promise<void> {
await db.delete('projects', dir);
}
+// ---------------------------------------------------------------------------
+// Collections
+
+/** Every collection, oldest first: the order they were made in. */
+export async function listCollectionRecords(): Promise<CollectionRecord[]> {
+ const db = await dbPromise;
+ const collections = await db.getAll('collections');
+ return collections.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
+}
+
+/** Puts `collection` on record, or replaces the one with its id. */
+export async function putCollectionRecord(collection: CollectionRecord): Promise<void> {
+ const db = await dbPromise;
+ await db.put('collections', collection);
+}
+
+/**
+ * Takes collection `id` off the record. The projects in it are kept, at the
+ * top level.
+ */
+export async function deleteCollectionRecord(id: string): Promise<void> {
+ const db = await dbPromise;
+ const tx = db.transaction(['collections', 'projects'], 'readwrite');
+ const projects = tx.objectStore('projects');
+ for (const record of await projects.getAll()) {
+ if (record.collectionId === id) await projects.put({ ...record, collectionId: undefined });
+ }
+ await tx.objectStore('collections').delete(id);
+ await tx.done;
+}
+
+/**
+ * Files the projects in `dirs` in collection `id`, or at the top level when
+ * it is undefined. Projects not on record are skipped.
+ */
+export async function fileProjectRecords(dirs: string[], id: string | undefined): Promise<void> {
+ const db = await dbPromise;
+ const tx = db.transaction('projects', 'readwrite');
+ for (const dir of dirs) {
+ const existing = await tx.store.get(dir);
+ if (existing) await tx.store.put({ ...existing, collectionId: id });
+ }
+ await tx.done;
+}
+
// ---------------------------------------------------------------------------
// Project bundles
diff --git a/apps/web/src/pages/dashboard.tsx b/apps/web/src/pages/dashboard.tsx
index 67d3fc49..c291b890 100644
--- a/apps/web/src/pages/dashboard.tsx
+++ b/apps/web/src/pages/dashboard.tsx
@@ -3,12 +3,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { useSearchParams } from "@solidjs/router";
-import { Match, Show, Switch, createEffect, createSignal, onCleanup, onMount } from "solid-js";
+import { Match, Show, Switch, createEffect, createMemo, createResource, createSignal, onCleanup, onMount } from "solid-js";
import { toast } from "somoto";
import { DashboardAccountView } from "@/components/dashboard/account-view";
import { DashboardAiCreditsView } from "@/components/dashboard/ai-credits-view";
import { DashboardBillingView } from "@/components/dashboard/billing-view";
+import { DashboardSidebarCollections } from "@/components/dashboard/collections-nav";
import { DashboardGetDesktopApp } from "@/components/dashboard/get-desktop-app";
import { DashboardHelpView } from "@/components/dashboard/help-view";
import { DashboardHomeView } from "@/components/dashboard/home-view";
@@ -28,14 +29,23 @@ import {
import { Separator } from "@/components/ui/separator";
import { useFullscreenState } from "@/hooks/use-fullscreen-state";
import { connectedAgents, fetchMcpStatus } from "@/lib/mcp";
-import { isDesktop, isWindowsDesktop, openProjectFolder, pickProjectFolder } from "@/projects";
+import {
+ isDesktop,
+ isWindowsDesktop,
+ listCollections,
+ openProjectFolder,
+ pickProjectFolder,
+ projectsRevision,
+ type CollectionRecord,
+} from "@/projects";
import { isInputTarget } from "@/utils";
-import type { DashboardView } from "@/components/dashboard/types";
+import type { DashboardView, ProjectScope } from "@/components/dashboard/types";
const DASHBOARD_VIEWS: readonly DashboardView[] = [
"home",
"projects",
+ "drafts",
"templates",
"ai-credits",
"billing",
@@ -96,7 +106,28 @@ export function DashboardPage() {
});
const view = (): DashboardView => parseView(params.dashboard);
- const setView = (next: DashboardView) => setParams({ dashboard: next }, { replace: true });
+ const setView = (next: DashboardView) => setParams({ dashboard: next, collection: undefined }, { replace: true });
+
+ // The projects view lists one collection's projects when the URL names it.
+ const [collections] = createResource(projectsRevision, () => listCollections(), { initialValue: [] });
+ const collectionId = (): string | null => {
+ const raw = params.collection;
+ return (Array.isArray(raw) ? raw[0] : raw) || null;
+ };
+ const openCollection = (collection: CollectionRecord) =>
+ setParams({ dashboard: "projects", collection: collection.id }, { replace: true });
+
+ const projectScope = createMemo((): ProjectScope => {
+ if (view() === "drafts") return { kind: "drafts" };
+ const collection = collections().find((c) => c.id === collectionId());
+ return collection ? { kind: "collection", collection } : { kind: "all" };
+ });
+
+ // A collection deleted (or never there) leaves the URL naming nothing: back to all.
+ createEffect(() => {
+ if (collections.loading || !collectionId()) return;
+ if (!collections().some((c) => c.id === collectionId())) setView("projects");
+ });
// Which navigation the sidebar shows. Landing on a settings view (deep link,
// reload) opens the settings navigation; the user row opens it by itself.
@@ -147,10 +178,20 @@ export function DashboardPage() {
<Show
when={settingsNavOpen()}
fallback={
- <DashboardSidebarSection>
- <DashboardSidebarItem active={view() === "home"} onClick={() => setView("home")} icon="home" label="Home" />
- <DashboardSidebarItem active={view() === "projects"} onClick={() => setView("projects")} icon="diffusion-project-file" label="Projects" />
- </DashboardSidebarSection>
+ <>
+ <DashboardSidebarSection>
+ <DashboardSidebarItem active={view() === "home"} onClick={() => setView("home")} icon="home" label="Home" />
+ </DashboardSidebarSection>
+ <DashboardSidebarSection title="Projects">
+ <DashboardSidebarItem active={projectScope().kind === "all" && view() === "projects"} onClick={() => setView("projects")} icon="view-grid" label="All" />
+ <DashboardSidebarItem active={view() === "drafts"} onClick={() => setView("drafts")} icon="navigation.folder" label="Drafts" />
+ <DashboardSidebarCollections
+ collections={collections()}
+ activeId={view() === "projects" ? collectionId() : null}
+ onOpen={openCollection}
+ />
+ </DashboardSidebarSection>
+ </>
}
>
<DashboardSidebarSection>
@@ -178,8 +219,8 @@ export function DashboardPage() {
<Match when={view() === "home"}>
<DashboardHomeView />
</Match>
- <Match when={view() === "projects"}>
- <DashboardProjectsView />
+ <Match when={view() === "projects" || view() === "drafts"}>
+ <DashboardProjectsView scope={projectScope()} />
</Match>
<Match when={view() === "ai-credits"}>
<DashboardAiCreditsView />
diff --git a/apps/web/src/projects/collections.ts b/apps/web/src/projects/collections.ts
new file mode 100644
index 00000000..db2ca73c
--- /dev/null
+++ b/apps/web/src/projects/collections.ts
@@ -0,0 +1,52 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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 {
+ deleteCollectionRecord,
+ fileProjectRecords,
+ listCollectionRecords,
+ putCollectionRecord,
+} from '@/lib/db';
+
+import { isDesktop, markProjectsChanged } from './host';
+
+import type { CollectionRecord } from '@/lib/db';
+
+export type { CollectionRecord };
+
+// Collections are the dashboard's folders: they live in the app's own
+// records, never on disk, and a project is in at most one. Every change bumps
+// `projectsRevision`, which the sidebar and the project grids both follow.
+
+/** Every collection, in the order they were made. */
+export async function listCollections(): Promise<CollectionRecord[]> {
+ if (!isDesktop()) return [];
+ return listCollectionRecords();
+}
+
+/** Makes an empty collection called `name`. */
+export async function createCollection(name: string): Promise<CollectionRecord> {
+ const collection: CollectionRecord = { id: crypto.randomUUID(), name, createdAt: new Date().toISOString() };
+ await putCollectionRecord(collection);
+ markProjectsChanged();
+ return collection;
+}
+
+/** Renames `collection` to `name`. */
+export async function renameCollection(collection: CollectionRecord, name: string): Promise<void> {
+ await putCollectionRecord({ ...collection, name });
+ markProjectsChanged();
+}
+
+/** Deletes collection `id`. Its projects stay on the list, at the top level. */
+export async function deleteCollection(id: string): Promise<void> {
+ await deleteCollectionRecord(id);
+ markProjectsChanged();
+}
+
+/** Files the projects in `dirs` in collection `id`, or at the top level when it is undefined. */
+export async function moveProjectsToCollection(dirs: string[], id: string | undefined): Promise<void> {
+ await fileProjectRecords(dirs, id);
+ markProjectsChanged();
+}
diff --git a/apps/web/src/projects/host.ts b/apps/web/src/projects/host.ts
index 5fd3eef2..3854c4d9 100644
--- a/apps/web/src/projects/host.ts
+++ b/apps/web/src/projects/host.ts
@@ -10,6 +10,7 @@ import { mainBridge } from '@/lib/ipc';
import {
findProjectRecords,
forgetProject as forgetProjectRecord,
+ getProjectRecord,
listProjectRecords,
moveProjectRecord,
rememberProject,
@@ -57,9 +58,12 @@ export const isDesktop = (): boolean => !!window.desktop;
export const isWindowsDesktop = (): boolean => window.desktop?.platform === "win32";
export const isMacOSDesktop = (): boolean => window.desktop?.platform === "darwin";
-/** Puts `project` on the list (or marks it just opened) and tells the views. */
-async function remember(project: ProjectInfo): Promise<void> {
- await rememberProject(project);
+/**
+ * Puts `project` on the list (or marks it just opened) and tells the views.
+ * A project new to the list is filed in `collectionId`, when one is given.
+ */
+async function remember(project: ProjectInfo, collectionId?: string): Promise<void> {
+ await rememberProject(project, collectionId);
setProjectsRevision((revision) => revision + 1);
}
@@ -168,15 +172,16 @@ export async function forgetProject(dir: string): Promise<void> {
}
/**
- * Creates a project and puts it on the list. It starts as a draft, called
- * "Untitled", in the app's own folder, so nothing is asked: where it lives and
- * what it is called are settled when it is saved (see `saveProject`).
+ * Creates a project and puts it on the list, filed in `collectionId` when one
+ * is given. It starts as a draft, called "Untitled", in the app's own folder,
+ * so nothing is asked: where it lives and what it is called are settled when
+ * it is saved (see `saveProject`).
*/
-export async function createProject(): Promise<ProjectInfo> {
+export async function createProject(collectionId?: string): Promise<ProjectInfo> {
if (!isDesktop()) throw new Error('Creating a project requires the desktop app.');
const project = await mainBridge.call(MAIN_CHANNELS.PROJECTS_CREATE, undefined);
- await remember(project);
+ await remember(project, collectionId);
return project;
}
@@ -259,12 +264,16 @@ export async function renameProject(dir: string, displayName: string): Promise<P
return project;
}
-/** Copies the project in `dir` next to itself and returns the copy (a new id), on the list. */
+/**
+ * Copies the project in `dir` next to itself and returns the copy (a new id),
+ * on the list in the collection the original is in.
+ */
export async function duplicateProject(dir: string): Promise<ProjectInfo> {
if (!dir) throw new Error('No project folder.');
const project = await mainBridge.call(MAIN_CHANNELS.PROJECTS_DUPLICATE, { dir });
- await remember(project);
+ const original = await getProjectRecord(dir);
+ await remember(project, original?.collectionId);
return project;
}
diff --git a/apps/web/src/projects/index.ts b/apps/web/src/projects/index.ts
index b61524d0..f50a52f5 100644
--- a/apps/web/src/projects/index.ts
+++ b/apps/web/src/projects/index.ts
@@ -4,3 +4,4 @@
export * from './host';
export * from './cover';
+export * from './collections';