Skip to content

The VS Code of video editing, built for agents.

TypeScript

Refactor recent projects display in DashboardHomeView for responsive grid layout

konstantin-paulus62c1f1533d31
diff --git a/apps/web/src/components/dashboard/home-view.tsx b/apps/web/src/components/dashboard/home-view.tsx
index 310883a4..c559bfea 100644
--- a/apps/web/src/components/dashboard/home-view.tsx
+++ b/apps/web/src/components/dashboard/home-view.tsx
@@ -13,6 +13,7 @@ import {
onCleanup,
} from "solid-js";
import { isServer } from "solid-js/web";
+import { createElementSize } from "@solid-primitives/resize-observer";
import { toast } from "somoto";
import {
@@ -80,8 +81,15 @@ type PromptTarget =
| { kind: "project"; project: ProjectInfo }
| { kind: "folder"; dir: string };
-/** Cards that fit the one row the design gives recents, the new one included. */
-const RECENT_COLUMNS = 5;
+/**
+ * Recents get one row, and as many cards as fit it at about this width — so a
+ * wider window shows more projects rather than bigger cards. The new-project
+ * card is one of them.
+ */
+const RECENT_CARD_WIDTH_PX = 180;
+const RECENT_MIN_COLUMNS = 2;
+/** The grid's `gap-x-0.5`. */
+const RECENT_GAP_PX = 2;
/** Recent projects the target menu offers before it gets unwieldy. */
const MENU_PROJECTS = 8;
@@ -140,6 +148,14 @@ export function DashboardHomeView() {
// is installed and signed in.
const model = createMemo(() => currentModel());
+ const [recentGrid, setRecentGrid] = createSignal<HTMLElement>();
+ const recentGridSize = createElementSize(recentGrid);
+ const recentColumns = createMemo(() => {
+ const width = recentGridSize.width ?? 0;
+ const fit = Math.floor((width + RECENT_GAP_PX) / (RECENT_CARD_WIDTH_PX + RECENT_GAP_PX));
+ return Math.max(RECENT_MIN_COLUMNS, fit);
+ });
+
const recentProjects = createMemo(() =>
[...(projects() ?? [])].sort(
(a, b) => parseTimestamp(b.modifiedAt) - parseTimestamp(a.modifiedAt),
@@ -450,32 +466,37 @@ export function DashboardHomeView() {
Recents
</h2>
</div>
- <div
- data-slot="card-grid"
- class="grid grid-cols-5 items-start gap-x-0.5 gap-y-3 px-4 pb-4"
- >
- <DashboardCardButton onClick={handleCreateProject}>
- <DashboardCardPreview class="bg-overlay-soft group-hover:bg-overlay">
- <Icon
- name="plus-add"
- class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 text-muted-foreground"
- />
- </DashboardCardPreview>
- <DashboardCardMeta title="New project" />
- </DashboardCardButton>
- <For each={recentProjects().slice(0, RECENT_COLUMNS - 1)}>
- {(project) => (
- <DashboardProjectCard
- project={project}
- active={selectedProject() === project.dir}
- onSelect={() => setSelectedProject(project.dir)}
- onDeselect={() => setSelectedProject(null)}
- onOpen={() => openProject(project)}
- onDelete={() => setPendingDelete(project)}
- onChanged={refetchProjects}
- />
- )}
- </For>
+ {/* Measured without its padding, so the width is what the cards share. */}
+ <div class="px-4 pb-4">
+ <div
+ ref={setRecentGrid}
+ data-slot="card-grid"
+ class="grid items-start gap-x-0.5 gap-y-3"
+ style={{ "grid-template-columns": `repeat(${recentColumns()}, minmax(0, 1fr))` }}
+ >
+ <DashboardCardButton onClick={handleCreateProject}>
+ <DashboardCardPreview class="bg-overlay-soft group-hover:bg-overlay">
+ <Icon
+ name="plus-add"
+ class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 text-muted-foreground"
+ />
+ </DashboardCardPreview>
+ <DashboardCardMeta title="New project" />
+ </DashboardCardButton>
+ <For each={recentProjects().slice(0, recentColumns() - 1)}>
+ {(project) => (
+ <DashboardProjectCard
+ project={project}
+ active={selectedProject() === project.dir}
+ onSelect={() => setSelectedProject(project.dir)}
+ onDeselect={() => setSelectedProject(null)}
+ onOpen={() => openProject(project)}
+ onDelete={() => setPendingDelete(project)}
+ onChanged={refetchProjects}
+ />
+ )}
+ </For>
+ </div>
</div>
</div>
</div>