import { type JSX, Show, onMount, onCleanup, createEffect } from "solid-js"; import { For } from "solid-js/web"; import { A, useLocation } from "@solidjs/router"; import Sidebar from "./Sidebar"; import NavSection from "./NavSection"; import { auth } from "../store/auth"; import { stats } from "../store/stats"; import { UserRole } from "../types/roles"; import type { CitizenSummary } from "../types/stats"; interface LayoutProps { children: JSX.Element; } export default function Layout(props: LayoutProps) { let heartbeatInterval: ReturnType | undefined; const location = useLocation(); onMount(() => { auth.initialize(); stats.load(); function handleExternalLinks(event: MouseEvent) { const anchor = (event.target as HTMLElement).closest("a"); if (!anchor || !anchor.href) return; try { const url = new URL(anchor.href); if (url.hostname !== window.location.hostname) { anchor.setAttribute("target", "_blank"); anchor.setAttribute("rel", "noopener noreferrer"); } } catch {} } document.addEventListener("click", handleExternalLinks); onCleanup(() => document.removeEventListener("click", handleExternalLinks)); }); createEffect(() => { location.pathname; stats.load(); }); createEffect(() => { clearInterval(heartbeatInterval); if (auth.user()) { auth.heartbeat(); heartbeatInterval = setInterval(() => auth.heartbeat(), 2 * 60 * 1000); } }); onCleanup(() => clearInterval(heartbeatInterval)); return ( <>
{props.children}
  • Citizens: {stats.data()?.citizens ?? "—"}
  • Online: {stats.data()?.online ?? "—"}
  • Posts Today: —
  • No birthdays today.
  • No posts yet.
  • No staff online.
); }