'use client'; import dynamic from 'next/dynamic'; import { useEffect, useRef, useState } from 'react'; import LeftPane from '@/components/LeftPane'; import RightPane from '@/components/RightPane'; import ToastStack from '@/components/Toasts'; import type { HoverTarget } from '@/components/hoverTypes'; import { useGameState } from '@/lib/useGameState'; import { useToasts } from '@/lib/useToasts'; import { diffSnapshots } from '@/lib/deriveEvents'; const Map = dynamic(() => import('@/components/Map'), { ssr: false }); export default function Home() { // Single polling source for the whole shell (v0.9.0): one /api/state loop, snapshot passed // down as props so later panes can share it without extra poll loops. applySnapshot (v0.10.0) // lets a pane push an action endpoint's full response snapshot in immediately. const { state, loading, error, refresh, applySnapshot } = useGameState(1000); // ISS-002 (v0.15.0): the side panels' hover target — shared here so hovering a row in // either pane highlights the matching plane/route/airports on the map. const [hovered, setHovered] = useState(null); // ISS-008 (v0.17.0): bottom-right toasts — action errors from both panes plus game events // derived by diffing consecutive snapshots (no server event feed exists). const { toasts, push, dismiss } = useToasts(); const onError = (message: string) => push('error', message); // Diff each new snapshot against the previous one → info toasts. When the window is hidden // and notifications are granted, mirror them as browser notifications too. const prevSnapshotRef = useRef(null); useEffect(() => { if (state === null) return; for (const event of diffSnapshots(prevSnapshotRef.current, state)) { push('info', event.message); if (document.hidden && 'Notification' in window && Notification.permission === 'granted') { new Notification('Flight Ops', { body: event.message }); } } prevSnapshotRef.current = state; }, [state, push]); return (
{/* ISS-021 (v0.20.0) — applySnapshot also reaches the left pane: its On board section's refuel/fly/abandon actions push their response snapshot into the shared state */} {/* v0.11.0 — the same polled snapshot drives the map's plane markers + route lines; ISS-010 (v0.18.0) — applySnapshot lets the airport popup's Relocate row push its action response into the shared state, exactly like RightPane does */}
); }