/* ═══════════════════════════════════════════════════════════════ ADMIN TITLE The layout knows which section you're in; only the page knows which record is on screen. Rather than have both write document.title and race (child effects run before parent effects, so the layout would win and the record name would never survive), the page publishes a string and the layout is the single writer. Null is the normal state. A page that publishes nothing, or one still loading, simply leaves the section title showing. ═══════════════════════════════════════════════════════════════ */ import { createContext, useContext, useEffect } from "react"; export const AdminTitleContext = createContext(null); /* Publish the name of whatever this page is showing. Clears on unmount, so navigating away can't leave a stale record name in the tab. */ export function useAdminDetail(name) { const setDetail = useContext(AdminTitleContext)?.setDetail; useEffect(() => { if (!setDetail) return undefined; setDetail(name || null); return () => setDetail(null); }, [setDetail, name]); }