the open page lists its bands in the nav
A third level, under the selected page only — every page has bands, and listing all of them would make the nav longer than the site. Announced by the builder rather than fetched again: it already reads them to know what it is looking at in the document, and it mounts exactly when a page is open. Cleared on unmount, or the nav keeps listing the last page's bands. Clicking one writes a third URL segment and the preview scrolls to it, keyed on the render count too so the position survives a save replacing the frame. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -60,3 +60,32 @@ export const pageFromParam = (pages: Page[] | null, value: string | null): Page
|
||||
if (!pages || !value) return null;
|
||||
return pages.find((page) => pageParam(page) === value) ?? null;
|
||||
};
|
||||
|
||||
/**
|
||||
* The selected page's sections, shared between the builder and the nav.
|
||||
*
|
||||
* ── Announced, not fetched twice ──
|
||||
*
|
||||
* The page builder already reads them — it needs their names and columns to know what it is looking at
|
||||
* in the rendered document — and the nav draws them as rows under the open page. Two fetchers would
|
||||
* agree until somebody renamed a band.
|
||||
*
|
||||
* The builder mounts whenever a page is selected, and the nav only draws these under the page that is
|
||||
* selected, so there is no state where the nav wants them and nothing has spoken.
|
||||
*
|
||||
* Null means nobody has said yet: the nav then draws no rows rather than an empty list, which would
|
||||
* read as "this page has no sections".
|
||||
*/
|
||||
export type NamedSection = { id: number; name: string };
|
||||
|
||||
const useSectionsList = defineChannel<NamedSection[] | null>('fofos-admin:sections', null);
|
||||
|
||||
export const useSections = () => {
|
||||
const [sections, setSections] = useSectionsList();
|
||||
|
||||
const setRef = useRef(setSections);
|
||||
setRef.current = setSections;
|
||||
const announceSections = useCallback((rows: NamedSection[] | null) => setRef.current(rows), []);
|
||||
|
||||
return { sections, announceSections };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user