Skip to content

The VS Code of video editing, built for agents.

TypeScript

Refactor project creation logic and streamline dashboard interactions

konstantin-paulus79a27580dfa5
diff --git a/apps/web/src/components/dashboard/home-view.tsx b/apps/web/src/components/dashboard/home-view.tsx
index 4b17cac2..ac1ee910 100644
--- a/apps/web/src/components/dashboard/home-view.tsx
+++ b/apps/web/src/components/dashboard/home-view.tsx
@@ -61,6 +61,7 @@ import {
DashboardCardMeta,
DashboardCardPreview,
createBackgroundClickHandler,
+ createNewProject,
} from "./shared";
import { parseTimestamp } from "./utils";
@@ -251,15 +252,9 @@ export function DashboardHomeView() {
setBusy(true);
try {
- if (!isDesktop()) {
- toast.error("Projects on disk are only available in the desktop app");
- return;
- }
- if (!(await ensureProjectsRoot())) return;
-
- const project = await createProject(generateProjectName());
+ const project = await createNewProject();
+ if (!project) return;
setSelectedProject(null);
- track("project_created");
refetchProjects();
openProject(project);
} catch (e) {
diff --git a/apps/web/src/components/dashboard/projects-view.tsx b/apps/web/src/components/dashboard/projects-view.tsx
index 0713bdeb..bb601574 100644
--- a/apps/web/src/components/dashboard/projects-view.tsx
+++ b/apps/web/src/components/dashboard/projects-view.tsx
@@ -2,7 +2,6 @@
* 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 { generateProjectName } from "@/lib/db";
import { toast } from "somoto";
import { For, createMemo, createResource, createSignal } from "solid-js";
import { useNavigate } from "@solidjs/router";
@@ -20,6 +19,7 @@ import {
DashboardCardButton,
DashboardCardPreview,
DashboardViewSection,
+ createNewProject,
} from "./shared";
import { DeleteProjectDialog } from "./delete-project-dialog";
import { DashboardProjectCard } from "./project-card";
@@ -30,9 +30,6 @@ import { projectRoute } from "@/hooks/use-project-route";
import { Icon } from "../ui/icon";
import { track } from "@/lib/analytics";
import {
- createProject,
- ensureProjectsRoot,
- isDesktop,
listProjects,
projectKey,
projectsRevision,
@@ -99,16 +96,8 @@ export function DashboardProjectsView() {
setCreating(true);
try {
- if (!isDesktop()) {
- toast.error("Projects on disk are only available in the desktop app");
- return;
- }
- // Waits for the roots to come back from the database, and asks for one
- // when there is none to wait for.
- if (!(await ensureProjectsRoot())) return;
-
- const project = await createProject(generateProjectName());
- track('project_created');
+ const project = await createNewProject();
+ if (!project) return;
refetchProjects();
openProject(project);
} catch (e) {
diff --git a/apps/web/src/components/dashboard/shared.tsx b/apps/web/src/components/dashboard/shared.tsx
index 21ec916d..88632e8b 100644
--- a/apps/web/src/components/dashboard/shared.tsx
+++ b/apps/web/src/components/dashboard/shared.tsx
@@ -20,9 +20,16 @@ import {
import { projectCoverKey, readProjectCover } from "@/projects";
import { Separator } from "../ui/separator";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
+import { toast } from "somoto";
import { track } from "@/lib/analytics";
-import { forgetProjectBundle } from "@/lib/db";
-import { deleteProject, type ProjectInfo } from "@/projects";
+import { forgetProjectBundle, generateProjectName } from "@/lib/db";
+import {
+ createProject,
+ deleteProject,
+ ensureProjectsRoot,
+ isDesktop,
+ type ProjectInfo,
+} from "@/projects";
type DashboardLabelValueProps = {
@@ -533,6 +540,27 @@ export function createBackgroundClickHandler(onCLick: () => void): JSX.EventHand
};
}
+/**
+ * Creates a fresh, randomly named project under the projects root and puts
+ * it on the list. Null — with the reason already shown — when there is no
+ * desktop to create it on, and when the user is asked where to put it and
+ * declines to say. The one flow behind every "new project": the card on each
+ * view, and the dashboard's keyboard shortcut.
+ */
+export async function createNewProject(): Promise<ProjectInfo | null> {
+ if (!isDesktop()) {
+ toast.error("Projects on disk are only available in the desktop app");
+ return null;
+ }
+ // Waits for the roots to come back from the database, and asks for one
+ // when there is none to wait for.
+ if (!(await ensureProjectsRoot())) return null;
+
+ const project = await createProject(generateProjectName());
+ track("project_created");
+ return project;
+}
+
/**
* Moves `project` to the Trash, and drops the bundle we were holding for it —
* the folder is gone, so the cached copy of it is stale.
diff --git a/apps/web/src/pages/dashboard.tsx b/apps/web/src/pages/dashboard.tsx
index 0dd573a8..9893661e 100644
--- a/apps/web/src/pages/dashboard.tsx
+++ b/apps/web/src/pages/dashboard.tsx
@@ -2,8 +2,9 @@
* 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 { useSearchParams } from "@solidjs/router";
-import { Match, Show, Switch, createEffect, createSignal, onMount } from "solid-js";
+import { useNavigate, useSearchParams } from "@solidjs/router";
+import { Match, Show, Switch, createEffect, 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";
@@ -14,6 +15,7 @@ import { DashboardHomeView } from "@/components/dashboard/home-view";
import { DashboardMcpView } from "@/components/dashboard/mcp-view";
import { DashboardProjectsView } from "@/components/dashboard/projects-view";
import { DashboardSettingsView } from "@/components/dashboard/settings-view";
+import { createNewProject } from "@/components/dashboard/shared";
import {
DashboardSidebarConnectCard,
DashboardSidebarHeader,
@@ -25,8 +27,11 @@ import {
} from "@/components/dashboard/sidebar";
import { Separator } from "@/components/ui/separator";
import { useFullscreenState } from "@/hooks/use-fullscreen-state";
+import { projectRoute } from "@/hooks/use-project-route";
+import { track } from "@/lib/analytics";
import { connectedAgents, fetchMcpStatus } from "@/lib/mcp";
-import { isDesktop } from "@/projects";
+import { isDesktop, projectKey } from "@/projects";
+import { isInputTarget } from "@/utils";
import type { DashboardView } from "@/components/dashboard/types";
@@ -63,9 +68,36 @@ function isSettingsView(view: DashboardView): boolean {
}
export function DashboardPage() {
+ const navigate = useNavigate();
const [params, setParams] = useSearchParams();
const isFullscreen = useFullscreenState();
+ let creating = false;
+ const handleShortcut = async (event: KeyboardEvent) => {
+ if (!(event.metaKey || event.ctrlKey) || event.shiftKey || event.altKey) return;
+ if (event.key.toLowerCase() !== "i" || isInputTarget(event)) return;
+
+ event.preventDefault();
+ if (creating) return;
+ creating = true;
+
+ try {
+ const project = await createNewProject();
+ if (!project) return;
+ track("project_opened");
+ navigate(projectRoute(projectKey(project)));
+ } catch (e) {
+ toast.error("Failed to create project", { description: (e as Error).message });
+ } finally {
+ creating = false;
+ }
+ };
+
+ onMount(() => {
+ window.addEventListener("keydown", handleShortcut);
+ onCleanup(() => window.removeEventListener("keydown", handleShortcut));
+ });
+
const view = (): DashboardView => parseView(params.dashboard);
const setView = (next: DashboardView) => setParams({ dashboard: next }, { replace: true });