Something went wrong. Try again.
spool is a community-first, lightweight discussion forum, issue tracker, and announcement hub for your project.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185export type IssueStatus = "open" | "in_progress" | "resolved" | "closed";
export const ISSUE_STATUS_OPTIONS: IssueStatus[] = ["open", "in_progress", "resolved", "closed"];
export const STATUS_LABELS: Record<IssueStatus, string> = { open: "open", in_progress: "in progress", resolved: "resolved", closed: "closed",};
export type User = { id: number; username: string; avatarUrl: string | null;};
export type ProjectInfo = { name: string; description: string | null; repoUrl: string | null;};
// A spool — one community/project on this instance, owned like a GitHub repo.export type Spool = { id: number; slug: string; name: string; description: string | null; repoUrl: string | null; ownerId: number; threadsLocked: boolean; owner: string; createdAt: string; // Only set on the single-spool detail fetch — whether the signed-in viewer // (if any) may start a new thread here right now. canStartThread?: boolean;};
export type SpoolSummary = Spool & { openIssues: number; totalIssues: number;};
// One message in a spool's threads view. A message with parentId === null// starts a thread; replies point at their thread's root.export type ThreadMessage = { id: number; parentId: number | null; body: string; author: string; authorAvatar: string | null; cutIssueNumber: number | null; createdAt: string;};
// A Tangled repo the logged-in user owns that hasn't yet been accepted or// declined for syncing into Spool.export type PendingTangledRepo = { uri: string; name: string; description: string | null; repoUrl: string;};
export type SearchResult = | { kind: "issue"; spoolSlug: string; issueNumber: number; title: string; status: IssueStatus; snippet: string } | { kind: "comment"; spoolSlug: string; issueNumber: number; issueTitle: string; snippet: string } | { kind: "message"; spoolSlug: string; messageRootId: number; author: string; snippet: string };
export type IssueSummary = { id: number; number: number; // per-spool issue number — what URLs and "#N" labels use title: string; status: IssueStatus; author: string; commentCount: number; createdAt: string;};
export type IssueComment = { id: number; body: string; author: string; authorAvatar: string | null; createdAt: string;};
export type IssueDetail = { id: number; // global id — the handle for mutations (status, title, comments) number: number; title: string; body: string; status: IssueStatus; author: string; authorAvatar: string | null; source: { messageId: number; author: string } | null; createdAt: string; comments: IssueComment[];};
async function request<T>(path: string, init?: RequestInit): Promise<T> { const res = await fetch(path, { headers: { "Content-Type": "application/json" }, ...init, }); if (!res.ok) { const data = await res.json().catch(() => null); throw new Error(data?.error ?? `Request failed (${res.status})`); } return res.json();}
export const api = { me: () => request<{ user: User | null }>("/api/me"), logout: () => request<{ ok: boolean }>("/auth/logout", { method: "POST" }),
project: () => request<ProjectInfo>("/api/project"),
spools: () => request<SpoolSummary[]>("/api/spools"), createSpool: (data: { name: string; description?: string; repoUrl?: string }) => request<Spool>("/api/spools", { method: "POST", body: JSON.stringify(data), }), spool: (slug: string) => request<Spool>(`/api/spools/${slug}`), updateSpool: ( slug: string, patch: { description?: string; repoUrl?: string; threadsLocked?: boolean } ) => request<Spool>(`/api/spools/${slug}`, { method: "PATCH", body: JSON.stringify(patch), }),
threads: (slug: string) => request<ThreadMessage[]>(`/api/spools/${slug}/threads`), postMessage: (slug: string, body: string, parentId?: number) => request<{ id: number }>(`/api/spools/${slug}/threads`, { method: "POST", body: JSON.stringify({ body, parentId }), }), cutMessage: (id: number) => request<{ id: number; number: number }>(`/api/messages/${id}/cut`, { method: "POST" }),
search: (q: string) => request<SearchResult[]>(`/api/search?q=${encodeURIComponent(q)}`),
pendingTangledRepos: () => request<PendingTangledRepo[]>("/api/tangled-repos/pending"), decideTangledRepos: (accepted: string[], declined: string[]) => request<{ ok: boolean }>("/api/tangled-repos/decide", { method: "POST", body: JSON.stringify({ accepted, declined }), }),
issues: (slug: string) => request<IssueSummary[]>(`/api/spools/${slug}/issues`), createIssue: (slug: string, data: { title: string; body: string }) => request<{ id: number }>(`/api/spools/${slug}/issues`, { method: "POST", body: JSON.stringify(data), }), issue: (slug: string, number: string) => request<IssueDetail>(`/api/spools/${slug}/issues/${number}`), updateIssue: (id: number, patch: { status?: IssueStatus; title?: string }) => request<unknown>(`/api/issues/${id}`, { method: "PATCH", body: JSON.stringify(patch), }), addComment: (id: number, body: string) => request<unknown>(`/api/issues/${id}/comments`, { method: "POST", body: JSON.stringify({ body }), }),};
export function timeAgo(iso: string): string { const seconds = Math.floor((Date.now() - new Date(iso).getTime()) / 1000); if (seconds < 60) return "just now"; const minutes = Math.floor(seconds / 60); if (minutes < 60) return `${minutes}m ago`; const hours = Math.floor(minutes / 60); if (hours < 24) return `${hours}h ago`; const days = Math.floor(hours / 24); if (days < 30) return `${days}d ago`; return new Date(iso).toLocaleDateString();}