Fetches active Temporary Flight Restrictions from the FAA website, filters by configured state (LOCATION_STATE env var), and displays a red warning banner at the top of the dashboard when TFRs are present. Data is cached for 30 minutes and degrades gracefully if the FAA is unreachable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
'use client'
|
|
|
|
import { useQuery } from '@tanstack/react-query'
|
|
import { getCurrentWeather, getForecast, getHistorical, getTfrs } from '@/lib/api'
|
|
import type { CurrentWeatherResponse, ForecastResponse, HistoricalResponse, TFRResponse } from '@/lib/types'
|
|
|
|
const STALE_TIME = 5 * 60 * 1000 // 5 minutes
|
|
const REFETCH_INTERVAL = 5 * 60 * 1000 // 5 minutes
|
|
|
|
export function useCurrentWeather(lat?: number, lon?: number) {
|
|
return useQuery<CurrentWeatherResponse>({
|
|
queryKey: ['weather', 'current', lat, lon],
|
|
queryFn: () => getCurrentWeather(lat, lon),
|
|
staleTime: STALE_TIME,
|
|
refetchInterval: REFETCH_INTERVAL,
|
|
refetchOnWindowFocus: true,
|
|
})
|
|
}
|
|
|
|
export function useForecast(lat?: number, lon?: number) {
|
|
return useQuery<ForecastResponse>({
|
|
queryKey: ['weather', 'forecast', lat, lon],
|
|
queryFn: () => getForecast(lat, lon),
|
|
staleTime: STALE_TIME,
|
|
refetchInterval: REFETCH_INTERVAL,
|
|
refetchOnWindowFocus: true,
|
|
})
|
|
}
|
|
|
|
export function useHistorical(date: string, lat?: number, lon?: number) {
|
|
return useQuery<HistoricalResponse>({
|
|
queryKey: ['weather', 'historical', date, lat, lon],
|
|
queryFn: () => getHistorical(date, lat, lon),
|
|
staleTime: STALE_TIME,
|
|
enabled: !!date,
|
|
})
|
|
}
|
|
|
|
const TFR_STALE_TIME = 30 * 60 * 1000 // 30 minutes
|
|
const TFR_REFETCH_INTERVAL = 30 * 60 * 1000 // 30 minutes
|
|
|
|
export function useTfrs() {
|
|
return useQuery<TFRResponse>({
|
|
queryKey: ['airspace', 'tfrs'],
|
|
queryFn: () => getTfrs(),
|
|
staleTime: TFR_STALE_TIME,
|
|
refetchInterval: TFR_REFETCH_INTERVAL,
|
|
})
|
|
}
|