NGU-Web/src/lib/navSections.ts
Zaldimmar 9daf7b1a4f Page editors: Retreats, Community, Resources, Organization and History built from sections
Each page is now a list of sections edited in Admin → Pages: a title
(30 characters at most, for the side nav), URL ID, blurb and accent,
its own content blocks, and an optional preset (Community blog, groups
map, region list, partner cards, events, timeline, NGU's details).
Migration 056 seeds every page as the code drew it and moves the
Organization editor's blocks and volunteering into its sections. The
Community blog's settings move into the Community editor. The header,
footer and side nav read each page's sections from the API.

The admin engine reads and writes nested collections to any depth.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 00:15:30 -05:00

41 lines
1.8 KiB
TypeScript

/* ═══════════════════════════════════════════════════════════════
NAV SECTIONS: the sections listed under each page in the header's
dropdowns, the mobile menu and the footer's site map
Every page's list comes from the page itself, so adding, moving
or renaming a section changes the menus too: the site pages'
sections (Pages → each page, GET /site-pages), and the front
page's bands it is showing, in the admin's order, each under its
heading (Front page → Sections).
═══════════════════════════════════════════════════════════════ */
import { useCallback } from 'react'
import { useSitePageHeadings } from './useSitePages.ts'
import { useFrontPage } from './useFrontPage.ts'
import { FRONT_PAGE_BANDS, bandShows } from './frontPageBands.ts'
export type NavSection = { label: string; hash: string }
export function useNavSections(): (path: string) => NavSection[] {
const { data: page } = useFrontPage()
const { data: sitePages } = useSitePageHeadings()
return useCallback(
(path: string) => {
if (path !== '/') {
return (sitePages?.[path.slice(1)] ?? []).map((section) => ({
label: section.title,
hash: `#${section.anchor}`,
}))
}
if (!page) return []
return page.sections.flatMap((section) => {
const band = FRONT_PAGE_BANDS[section.section]
if (!band?.id || !bandShows(page, section.section)) return []
return [{ label: section.title || band.title, hash: `#${band.id}` }]
})
},
[page, sitePages],
)
}