import { useQuery } from '@tanstack/react-query'; import { format } from 'date-fns'; import { Bell } from 'lucide-react'; import api from '@/lib/api'; import type { DashboardData, UpcomingResponse } from '@/types'; import { useSettings } from '@/hooks/useSettings'; import StatsWidget from './StatsWidget'; import TodoWidget from './TodoWidget'; import CalendarWidget from './CalendarWidget'; import UpcomingWidget from './UpcomingWidget'; import WeekTimeline from './WeekTimeline'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { DashboardSkeleton } from '@/components/ui/skeleton'; function getGreeting(): string { const hour = new Date().getHours(); if (hour < 5) return 'Good night.'; if (hour < 12) return 'Good morning.'; if (hour < 17) return 'Good afternoon.'; if (hour < 21) return 'Good evening.'; return 'Good night.'; } export default function DashboardPage() { const { settings } = useSettings(); const { data, isLoading } = useQuery({ queryKey: ['dashboard'], queryFn: async () => { const now = new Date(); const today = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`; const { data } = await api.get(`/dashboard?client_date=${today}`); return data; }, }); const { data: upcomingData } = useQuery({ queryKey: ['upcoming', settings?.upcoming_days], queryFn: async () => { const days = settings?.upcoming_days || 7; const { data } = await api.get(`/upcoming?days=${days}`); return data; }, }); if (isLoading) { return (
); } if (!data) { return (
Failed to load dashboard
); } return (
{/* Header — greeting + date */}

{getGreeting()}

{format(new Date(), 'EEEE, MMMM d, yyyy')}

{/* Week Timeline */} {upcomingData && (
)} {/* Stats Row */}
{/* Main Content — 2 columns */}
{/* Left: Upcoming feed (wider) */}
{upcomingData && upcomingData.items.length > 0 ? ( ) : ( Upcoming

Nothing upcoming. Enjoy the quiet.

)}
{/* Right: Today's events + todos stacked */}
{/* Active Reminders */} {data.active_reminders.length > 0 && (
Active Reminders
{data.active_reminders.map((reminder) => (

{reminder.title}

{format(new Date(reminder.remind_at), 'MMM d, yyyy h:mm a')}

))}
)}
); }