'use client' import { useCurrentWeather, useForecast, useHistorical } from '@/hooks/use-weather' import { AssessmentBadge } from '@/components/weather/assessment-badge' import { WindSpeedChart } from '@/components/weather/wind-speed-chart' import { WindDirectionChart } from '@/components/weather/wind-direction-chart' import { ThresholdControls } from '@/components/weather/threshold-controls' import { RefreshCountdown } from '@/components/weather/refresh-countdown' import { StaleDataBanner } from '@/components/weather/stale-data-banner' import { Collapsible } from '@/components/ui/collapsible' import { useQueryClient } from '@tanstack/react-query' import { Loader2, AlertCircle } from 'lucide-react' import { subDays, format } from 'date-fns' export default function DashboardPage() { const queryClient = useQueryClient() // Fetch current weather and forecast const { data: currentWeather, isLoading: isLoadingCurrent, error: currentError, } = useCurrentWeather() const { data: forecast, isLoading: isLoadingForecast, error: forecastError, } = useForecast() // Fetch yesterday's data for comparison const yesterday = format(subDays(new Date(), 1), 'yyyy-MM-dd') const { data: historicalData, isLoading: isLoadingHistorical, } = useHistorical(yesterday) // Handle refresh const handleRefresh = async () => { await queryClient.invalidateQueries({ queryKey: ['weather'] }) } // Loading state if (isLoadingCurrent || isLoadingForecast) { return (
Loading weather data...
{(currentError as Error)?.message || (forecastError as Error)?.message || 'An unexpected error occurred'}
No weather data available
{currentWeather.location.name} ({currentWeather.location.lat.toFixed(2)}, {currentWeather.location.lon.toFixed(2)})
)}Data updates every 5 minutes. Forecast generated at{' '} {format(new Date(forecast.generated_at), 'PPpp')}
{isLoadingHistorical && (Loading historical comparison data...
)}