Skip to content

Admin portal Phase 5: notices + site-wide banners - #179

Merged
neuromechanist merged 5 commits into
mainfrom
feature/issue-178-phase5-notices
Jul 25, 2026
Merged

neuromechanist merged 5 commits into
mainfrom
feature/issue-178-phase5-notices

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Closes #178. Phase 5 of epic #158 — the last phase, so this completes the epic.

Adds /admin/notices (list / create / delete) and renders active notices as stacking site-wide banners on every page.

What's here

  • src/lib/notices-api.ts — public banner feed + admin CRUD, every fetch deadline-bounded
  • src/pages/api/notices.ts — same-origin no-store JSON feed for the banner
  • src/components/SiteNotices.astro — stacking banners in Base.astro, one tone per level, per-notice dismissal
  • src/pages/admin/notices.astro — create form (level / audience / expiry, with live consequence hints and a 1000-char counter) and a list that marks lapsed notices
  • Notices tab enabled, so every tab in ADMIN_TABS is now live

Decisions worth reviewing

The banner is client-fetched, never server-rendered. index.astro, discover.astro, and dataset/[id].astro all set real edge-cache headers with long stale-while-revalidate windows — 12 h on the landing page, 24 h on dataset detail. An SSR'd banner would be frozen into that cached HTML: a new outage notice invisible until s-maxage elapsed, a resolved one lingering for the whole SWR window. Fetching from a no-store same-origin route keeps page HTML cacheable and the banner current.

Expiry is computed client-side. Per nemar-cli#1024 (filed from this work), the backend compares an ISO-8601 expires_at against SQLite's datetime('now') as strings; T sorts after a space, so a notice expiring later today is still served as active until the next UTC day. Verified with sqlite3. Both the banner and the admin list therefore compute expiry themselves — the nemar-cli CLI already does the same, so this matches existing behaviour rather than inventing a workaround.

Dismissal is per-notice and level-dependent. Keyed by notice id, so dismissing a standing announcement never suppresses a maintenance banner posted later. info/warning dismissals persist in localStorage — a months-long "the site has moved" banner that returned on every visit would be an irritation. critical uses sessionStorage, so an active outage can be pushed aside but re-asserts on the next visit.

Levels are info | warning | critical, fixed upstream by both a zod enum and migration 0016's CHECK. Each gets a distinct tone (info reads as a tip, warning amber, critical as an outage). A separate maintenance level would need an upstream migration and is not attempted here.

Messages render via textContent, never innerHTML. Admin-authored is not the same as trusted markup, and a banner on every page is the last place to allow injection.

Bug caught by running it

/api/notices initially returned nothing for anonymous visitors. dashboardApiBase() infers "SSR" from the presence of a cookie header, but an anonymous request has none, so it resolved to the relative /api/v1 — unfetchable server-side. Because the banner fails soft, the symptom was not an error but a banner that silently never appeared for signed-out visitors, i.e. most of the marketing surface. Fixed with an explicit baseUrl passed by the route; the cookie heuristic stays correct for the authenticated admin clients that rely on it.

Testing

  • bun run test — 837 passing (32 new). bun run typecheck 0 errors, bun run lint clean, bun run build clean.
  • Exercised end-to-end against a local fixture API (PUBLIC_API_BASE_URL), not just unit tests:
    • three notices stack in the right order — critical above warning above info
    • a lapsed notice the fixture deliberately still serves is filtered out client-side (the #1024 path)
    • role="alert" on critical only, role="status" on the rest
    • light and dark both verified by screenshot
    • dismissing the standing notice keeps it gone across navigation; after a new session the critical banner returns while the dismissed one stays dismissed
    • create → backend received level: critical with 18:30 local correctly stored as 01:30Z the next day; delete → row removed via the typed-confirmation dialog
  • Gate re-verified on the new route: anonymous /admin/notices 302s to /login?next=…, admin gets 200.

Still worth a real admin pass on the preview deploy against live data, same as Phases 3 and 4.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Admin portal Phase 5: Notices (admin CRUD + site-wide banners)

1 participant