Live data: SSE-driven charts + live admin dashboard

Live data: SSE-driven charts + live admin dashboard

#17 in tonybierman/dx-blog — merged 2026-05-30

Builds out the real-time layer on top of the existing per-post SSE hub, in two parts.

1. Server-driven live charts (5d3…→ first commit)

  • The livechart MDX embed now subscribes to the post's SSE channel instead of running a client-side timer with synthetic data.
  • New topic-keyed LiveEvent::Data { topic, value }; the hub keeps a per-(post, topic) ring buffer and live_handler replays the backlog on connect so late joiners see recent history (no client change — backfill rides the same data events).
  • A background producer samples real host CPU (/proc/stat) and memory (/proc/meminfo) and publishes them on the cpu/mem topics; it resolves the chart post by slug so reseeds keep working.
  • push_data_point server fn for manual/ingest pushes.

2. Live admin dashboard & moderation queue (second commit)

  • A separate, authorized, site-wide admin channel (AdminEvent + singleton admin_tx on LiveHub) — kept distinct from the public per-post channel so pending/unmoderated comment bodies never leak. The admin stream carries notification metadata only.
  • GET /api/admin/live is gated on a signed-in COMMENTS_MODERATE holder (via the session cookie); returns 403 on refusal.
  • Publishes wired into create_comment (incl. pending), moderate_comment (every status), delete_comment, add_reaction.
  • use_admin_live client hook mirrors use_live (SSR-safe, web-gated, reactive on permission).
  • Dashboard: new Reactions tile, a live activity feed (moderators only), authoritative refetch on comment events + local reaction delta. Moderation queue refetches live on comment events.
  • Activity/status badges use the theme accent (brand-*).

Docs & verification

  • docs/live-data.md documents both the per-post and admin streams.
  • TODO_VERIFICATION.md has the end-to-end manual checklist.

Checks

  • cargo check / cargo clippy -D warnings pass on both targets (server,sqlite and wasm web); cargo fmt --check clean.
  • Live charts verified end-to-end in the running app. The admin-dashboard flows are covered by the TODO_VERIFICATION.md checklist (not yet manually driven).

🤖 Generated with Claude Code

Last updated 2026-05-31