'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...

) } // Error state if (currentError || forecastError) { return (

Failed to load weather data

{(currentError as Error)?.message || (forecastError as Error)?.message || 'An unexpected error occurred'}

) } // No data state if (!currentWeather || !forecast) { return (

No weather data available

) } // Get best flyable window const bestWindow = forecast.flyable_windows && forecast.flyable_windows.length > 0 ? forecast.flyable_windows[0] : undefined return (
{/* Header */}

#ShouldIFly TPG?

{currentWeather.location.name && (

{currentWeather.location.name} ({currentWeather.location.lat.toFixed(2)}, {currentWeather.location.lon.toFixed(2)})

)}
{/* Stale Data Warning */} {/* Assessment Badge */}
{/* Charts */}
{/* Threshold Controls - Collapsible */} {/* Refresh Countdown */} {/* Footer Info */}

Data updates every 5 minutes. Forecast generated at{' '} {format(new Date(forecast.generated_at), 'PPpp')}

{isLoadingHistorical && (

Loading historical comparison data...

)}
) }