Skip to content

g1t/apps/web/app/lib/workspace-projects.server.ts

22 lines1,065 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Navigation: the workspace's own page with tabs, pins and recent in the sidebar1import type { Project, Result, Viewer } from "@g1t/contracts";
2
3import { shortCache } from "./cache.server";
4import { projects } from "./services.server";
5
6/** How long one isolate keeps a person's list of a workspace's projects. */
7export 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 */
14export 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. */
20export 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}