import { useEffect, useState, type ReactNode } from "react"; import { NavLink, Outlet, useParams } from "react-router-dom"; import { api, type Spool } from "../api"; import { useAuth } from "../auth"; // Child pages (e.g. IssuePage) call this, via useOutletContext, to render // their own breadcrumb on the same line as the repo URL above, and to read // the spool this layout already fetched (e.g. ThreadsPage checks threadsLocked). export type SpoolLayoutContext = { setBreadcrumb: (breadcrumb: ReactNode) => void; spool: Spool }; // Wraps every /s/:slug/* page: fetches the spool once, renders its header // (name, owner, threads/issues tabs), and the child page below. export function SpoolLayout() { const { slug } = useParams<{ slug: string }>(); const { user } = useAuth(); const [spool, setSpool] = useState(null); const [error, setError] = useState(null); const [breadcrumb, setBreadcrumb] = useState(null); useEffect(() => { setSpool(null); api.spool(slug!).then(setSpool).catch((e) => setError(e.message)); }, [slug]); if (error) return

error: {error}

; if (!spool) return

loading…

; return (

{spool.name}

@{spool.owner} {spool.repoUrl && ( <> {" · "} {spool.repoUrl.replace(/^https?:\/\//, "")} )} {breadcrumb && ( <> {" · "} {breadcrumb} )}

); }