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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869import { 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<Spool | null>(null); const [error, setError] = useState<string | null>(null); const [breadcrumb, setBreadcrumb] = useState<ReactNode>(null);
useEffect(() => { setSpool(null); api.spool(slug!).then(setSpool).catch((e) => setError(e.message)); }, [slug]);
if (error) return <p className="state-line">error: {error}</p>; if (!spool) return <p className="state-line">loading…</p>;
return ( <div className="spool-layout"> <div className="spool-head"> <div> <h1 className="spool-name">{spool.name}</h1> <p className="meta meta-dim"> @{spool.owner} {spool.repoUrl && ( <> {" · "} <a href={spool.repoUrl}>{spool.repoUrl.replace(/^https?:\/\//, "")}</a> </> )} {breadcrumb && ( <> {" · "} {breadcrumb} </> )} </p> </div> <nav className="filter-tabs"> <NavLink to={`/s/${slug}`} end className={({ isActive }) => `tab ${isActive ? "tab-active" : ""}`}> threads </NavLink> <NavLink to={`/s/${slug}/issues`} className={({ isActive }) => `tab ${isActive ? "tab-active" : ""}`}> issues </NavLink> {user?.id === spool.ownerId && ( <NavLink to={`/s/${slug}/settings`} className={({ isActive }) => `tab ${isActive ? "tab-active" : ""}`}> settings </NavLink> )} </nav> </div> <div className="spool-body"> <Outlet context={{ setBreadcrumb, spool } satisfies SpoolLayoutContext} /> </div> </div> );}