import { useCallback, useEffect, useState, type FormEvent } from "react"; import { Link, useOutletContext, useParams } from "react-router-dom"; import { api, timeAgo, type IssueDetail, type IssueStatus, ISSUE_STATUS_OPTIONS, STATUS_LABELS } from "../api"; import { useAuth } from "../auth"; import { StatusBadge } from "../components/StatusBadge"; import type { SpoolLayoutContext } from "../components/SpoolLayout"; export function IssuePage() { const { slug, number } = useParams<{ slug: string; number: string }>(); const { user } = useAuth(); const { setBreadcrumb } = useOutletContext(); const [issue, setIssue] = useState(null); const [error, setError] = useState(null); const [editingTitle, setEditingTitle] = useState(false); const load = useCallback(() => { api.issue(slug!, number!).then(setIssue).catch((e) => setError(e.message)); }, [slug, number]); useEffect(load, [load]); // Render this page's breadcrumb up in SpoolLayout's header, on the same // line as the repo URL, rather than as its own line down here. useEffect(() => { if (!issue) return; setBreadcrumb( <> issues / #{issue.number} ); return () => setBreadcrumb(null); }, [issue, slug, setBreadcrumb]); if (error) return

error: {error}

; if (!issue) return

loading…

; async function setStatus(status: IssueStatus) { await api.updateIssue(issue!.id, { status }); load(); } async function saveTitle(e: FormEvent) { e.preventDefault(); const title = String(new FormData(e.currentTarget).get("title")); try { await api.updateIssue(issue!.id, { title }); setEditingTitle(false); load(); } catch (err) { setError((err as Error).message); } } async function addComment(e: FormEvent) { e.preventDefault(); const form = e.currentTarget; const body = String(new FormData(form).get("body")); try { await api.addComment(issue!.id, body); form.reset(); load(); } catch (err) { setError((err as Error).message); } } return (
{/* The whole issue scrolls as one document — only the spool header above (from SpoolLayout) stays anchored. */}
{editingTitle ? (
) : (

{issue.title} {user && ( )}

)}
opened {timeAgo(issue.createdAt)} by @{issue.author} {user && ( )}
{issue.source && (

✂ cut from a thread by @ {issue.source.author}

)}
{issue.body &&
{issue.body}
}

thread ({issue.comments.length})

    {issue.comments.map((comment) => (
  • @{comment.author}{" "} {timeAgo(comment.createdAt)}

    {comment.body}

  • ))}
{user ? (