| 1 | import type { Project, Result, Viewer } from "@g1t/contracts"; |
| 2 | |
| 3 | import { shortCache } from "./cache.server"; |
| 4 | import { projects } from "./services.server"; |
| 5 | |
| 6 | /** How long one isolate keeps a person's list of a workspace's projects. */ |
| 7 | export const PROJECTS_TTL_MS = 15_000; |
| 8 | |
| 9 | /** |
| 10 | * A workspace's projects as the viewer may see them: one listing, kept for |
| 11 | * a few seconds per person and workspace (lib/cache.server.ts), so the |
| 12 | * sidebar, the workspace's tabs and its Projects page share it. |
| 13 | */ |
| 14 | export function workspaceProjects(slug: string, viewer: Viewer): Promise<Result<Project[]>> { |
| 15 | const workspace = slug.toLowerCase(); |
| 16 | return shortCache(`shell:projects:${viewer?.id ?? "visitor"}:${workspace}`, PROJECTS_TTL_MS, () => projects.list(workspace, viewer)); |
| 17 | } |
| 18 | |
| 19 | /** What a project is in the sidebar and the command palette. */ |
| 20 | export function shortcutOf(project: Project): { namespace: string; name: string; title: string; isPrivate: boolean } { |
| 21 | return { namespace: project.workspace, name: project.slug, title: project.name, isPrivate: project.private }; |
| 22 | } |