"use client"; import { useQuery } from "@tanstack/react-query"; import { useState } from "react"; import { AppShell } from "@/components/layout/app-shell"; import { CharacterCard } from "@/components/features/character-card"; import { TodaysAdventure } from "@/components/features/todays-adventure"; import { DailyReflection } from "@/components/features/daily-reflection"; import { QuestGiverSidebar, ReadingWidget } from "@/components/features/sidebar-widgets"; import { DaySwitcher } from "@/components/features/day-switcher"; import { CatchUpCard } from "@/components/features/catch-up-card"; import { QuickLogPanel } from "@/components/features/quick-log-panel"; import { formatDisplayDate, todayString } from "@/lib/dates-client"; async function fetchDashboard(date?: string) { const url = date ? `/api/dashboard?date=${date}` : "/api/dashboard"; const res = await fetch(url); if (!res.ok) throw new Error("Failed to load dashboard"); return res.json(); } export default function HomePage() { const [activeDate, setActiveDate] = useState(undefined); const { data, isLoading, error } = useQuery({ queryKey: ["dashboard", activeDate], queryFn: () => fetchDashboard(activeDate), }); if (isLoading) { return (
Loading your adventure...
); } if (error || !data) { return (
Could not load dashboard. Is the database running?
); } const date = data.today?.date ?? data.dateContext?.logicalToday ?? todayString(); const ctx = data.dateContext; return (
{ctx && ( )}

{formatDisplayDate(date)}

{data.catchUpGaps?.length > 0 && ( )}
{data.today && ( )}
); }