From 063a7ee66900d6be9d0cbc50eb94df3607cee670 Mon Sep 17 00:00:00 2001 From: bubulux Date: Wed, 25 Nov 2026 17:22:50 +0100 Subject: [PATCH] Projects: picture and description, cards grouped by workspace; Workspaces in Settings (#426) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - A project has a description and a picture (migration 0012): the picture is uploaded from the computer, scaled in the browser to fit 2000 × 2000, stored in R2, at most 5 MB and 4 MP on the server (size read from the header); not a file of the project. Both in Settings › General. - All projects are cards grouped by workspace: picture, name, description, files, created; open, rename, delete. - Workspaces leave Account: a Workspaces section in Settings with an overview of every workspace you belong to and one page per workspace (rename, members and roles, a new project). Co-Authored-By: Claude Opus 5.5 --- apps/studio/src/api.ts | 13 ++- apps/studio/src/apps/AccountPage.tsx | 66 +++++++++----- apps/studio/src/apps/ProjectApp.tsx | 85 +++++++++++++++---- apps/studio/src/apps/SettingsApp.tsx | 22 +++-- apps/studio/src/projects.ts | 28 +++++- apps/studio/src/shell.css | 21 +++++ .../migrations/0012_project_picture.sql | 5 ++ apps/worker/src/images.ts | 28 ++++++ apps/worker/src/projects.ts | 60 ++++++++++++- apps/worker/test/routes/projects.test.ts | 45 ++++++++++ apps/worker/test/routes/tenancy.test.ts | 3 + docs/api.md | 5 +- docs/data-model.md | 2 +- docs/features/desktop.md | 2 +- 14 files changed, 331 insertions(+), 54 deletions(-) create mode 100644 apps/worker/migrations/0012_project_picture.sql create mode 100644 apps/worker/test/routes/projects.test.ts diff --git a/apps/studio/src/api.ts b/apps/studio/src/api.ts index 4a0d9f5a..583a8f18 100644 --- a/apps/studio/src/api.ts +++ b/apps/studio/src/api.ts @@ -3,7 +3,7 @@ import type { FrameValues } from "@openclapper/model"; export interface Me { user: { id: string; email: string; name: string | null }; workspaces: { id: string; name: string; role: WorkspaceRole; personal: boolean }[] } export type WorkspaceRole = "owner" | "admin" | "editor" | "viewer"; -export interface Project { id: string; name: string; workspace_id: string; created_at: string; updated_at: string | null; file_count: number; canvas_live: CanvasLive; /** The master timeline: the order of the project's timelines. */ master: string[]; /** The extensions switched on (docs/rewrite/08-extensions.md). */ extensions: string[] } +export interface Project { id: string; name: string; workspace_id: string; created_at: string; updated_at: string | null; file_count: number; canvas_live: CanvasLive; /** The master timeline: the order of the project's timelines. */ master: string[]; /** The extensions switched on (docs/rewrite/08-extensions.md). */ extensions: string[]; /** What it is about (#426). */ description: string; /** When its picture was set; null: none. */ picture_at: string | null } /** How watchers of a canvas see it change while someone edits it: at once, or every few seconds. */ export type CanvasLive = "realtime" | "gradual"; export interface ServerBuild { version: string; commit: string; instance: string } @@ -60,7 +60,16 @@ export const signIn = (email: string, password: string) => send("POST", export const signOut = () => fetch("/api/auth/logout", { method: "POST", credentials: "same-origin" }).then(() => undefined); export const fetchProjects = () => get<{ projects: Project[] }>("/api/projects").then((r) => r.projects); -export const putProject = (id: string, body: { name: string; workspace_id?: string; canvas_live?: CanvasLive; master?: string[]; extensions?: string[] }) => send<{ project: Project }>("PUT", `/api/projects/${id}`, body).then((r) => r.project); +/** A project's picture (#426): its URL, versioned by when it was set; null without one. */ +export const projectPictureUrl = (p: Project) => (p.picture_at ? `/api/projects/${p.id}/picture?v=${encodeURIComponent(p.picture_at)}` : null); +export async function putProjectPicture(id: string, body: Blob): Promise { + const res = await fetch(`/api/projects/${id}/picture`, { method: "PUT", credentials: "same-origin", headers: { "content-type": "application/octet-stream" }, body }); + const b = (await res.json().catch(() => ({}))) as { project?: Project; error?: string }; + if (!res.ok || !b.project) throw new ApiError(res.status, b.error ?? `Upload failed (${res.status})`); + return b.project; +} +export const deleteProjectPicture = (id: string) => send<{ project: Project }>("DELETE", `/api/projects/${id}/picture`).then((r) => r.project); +export const putProject = (id: string, body: { name: string; workspace_id?: string; canvas_live?: CanvasLive; master?: string[]; extensions?: string[]; description?: string }) => send<{ project: Project }>("PUT", `/api/projects/${id}`, body).then((r) => r.project); export const deleteProject = (id: string) => send<{ deleted: string }>("DELETE", `/api/projects/${id}`); /** A file as the API gives it (docs/api.md). `body` and `refs` come with single-file answers and with lists that ask for them. */ diff --git a/apps/studio/src/apps/AccountPage.tsx b/apps/studio/src/apps/AccountPage.tsx index 42106574..86730b87 100644 --- a/apps/studio/src/apps/AccountPage.tsx +++ b/apps/studio/src/apps/AccountPage.tsx @@ -117,21 +117,11 @@ function WorkspaceCard({ ws, meId, onChanged }: { ws: Workspace; meId: string; o ); } -/** Settings › Account: who is signed in, the password, and the workspaces they are in with members and roles. */ +/** Settings › Account: who is signed in and the password; nothing else (#426: workspaces have their own section). */ export function AccountPage() { const user = useUser(); - const [list, setList] = useState(null); - const [error, setError] = useState(null); - const load = () => fetchWorkspaces().then((w) => { setList(w); setError(null); }, (e: Error) => setError(e.message)); - useEffect(() => { void load(); }, []); if (user.status !== "signed-in") return null; const me = user.me.user; - const newWorkspace = async () => { - const name = await prompt({ title: "New workspace", label: "Name", confirmLabel: "Create" }); - if (!name) return; - // The list of one's workspaces is part of who is signed in: read that again too. - try { await putWorkspace(crypto.randomUUID(), name); await load(); void boot(); } catch (e) { toastError(e); } - }; return ( <> @@ -144,15 +134,51 @@ export function AccountPage() { - -
- Every project belongs to one workspace; its members see it with their role. Your personal workspace is yours; invite people into a shared one. Viewers look, editors change content, admins also manage editors and viewers, the owner also admins. - -
- {error &&

{error}

} - {!list && !error && } - {list?.map((w) => void load()} />)} -
); } + +/** The workspaces one belongs to, read once per Settings window and again after a change. */ +export function useWorkspaceList(): { list: Workspace[] | null; error: string | null; reload: () => void } { + const [list, setList] = useState(null); + const [error, setError] = useState(null); + const reload = () => { void fetchWorkspaces().then((w) => { setList(w); setError(null); }, (e: Error) => setError(e.message)); }; + useEffect(reload, []); + return { list, error, reload }; +} + +/** + * Settings › Workspaces (#426): every workspace you belong to, with your role, its members and projects; one opens on + * its own page. A workspace is shared, so it is a page of Settings, not a file. + */ +export function WorkspacesPage({ list, error, reload, onOpen }: { list: Workspace[] | null; error: string | null; reload: () => void; onOpen: (id: string) => void }) { + const newWorkspace = async () => { + const name = await prompt({ title: "New workspace", label: "Name", confirmLabel: "Create" }); + if (!name) return; + // The list of one's workspaces is part of who is signed in: read that again too. + try { const id = crypto.randomUUID(); await putWorkspace(id, name); reload(); void boot(); onOpen(id); } catch (e) { toastError(e); } + }; + return ( + +
+ Every project belongs to one workspace; its members see it with their role. Your personal workspace is yours; invite people into a shared one. Viewers look, editors change content, admins also manage members. + +
+ {error &&

{error}

} + {!list && !error && } + {list?.map((w) => ( + + ))} +
+ ); +} + +/** One workspace's page: rename, members and roles, a new project in it. */ +export function WorkspacePage({ ws, onChanged }: { ws: Workspace; onChanged: () => void }) { + const user = useUser(); + if (user.status !== "signed-in") return null; + return ; +} diff --git a/apps/studio/src/apps/ProjectApp.tsx b/apps/studio/src/apps/ProjectApp.tsx index d06dd498..67e5d505 100644 --- a/apps/studio/src/apps/ProjectApp.tsx +++ b/apps/studio/src/apps/ProjectApp.tsx @@ -1,9 +1,9 @@ import { useEffect, useState } from "preact/hooks"; -import { Badge, Button, EmptyState, FormField, PropertyList, PropertyRow, PropertySection, Segmented, Select, SettingsGroup, Table, TextInput } from "@openclapper/design"; -import { ApiError } from "../api"; +import { AppIcon, Badge, Button, EmptyState, FormField, PropertyList, PropertyRow, PropertySection, Segmented, Select, SettingsGroup, TextArea, TextInput } from "@openclapper/design"; +import { ApiError, projectPictureUrl, type Project } from "../api"; import { confirm, prompt, toast, toastError } from "../hosts"; import { switchProject } from "../project"; -import { removeProject, saveProject, setCanvasLive, useProjects } from "../projects"; +import { removeProject, saveProject, setCanvasLive, setDescription, setPicture, useProjects } from "../projects"; import { useUser } from "../user"; import { useCatalogue } from "../props"; import { NamingPage } from "./project/Naming"; @@ -95,6 +95,9 @@ export function ProjectPage({ tab, winId, projectId }: { tab: ProjectTab; winId: + + + @@ -120,22 +123,70 @@ export function ProjectPage({ tab, winId, projectId }: { tab: ProjectTab; winId: {editable.length > 1 && + {pic && } + + JPEG, PNG or WebP; a larger one is scaled to fit 2000 × 2000. + +