export interface WeatherData { latitude: number; longitude: number; generationtime_ms: number; utc_offset_seconds: number; timezone: string; timezone_abbreviation: string; elevation: number; current_units: { time: string; interval: string; temperature_2m: string; weather_code: string; }; current: { time: string; interval: number; temperature_2m: number; weather_code: number; }; hourly_units: { time: string; temperature_2m: string; weather_code: string; }; hourly: { time: string[]; temperature_2m: number[]; weather_code: number[]; }; daily_units: { time: string; weather_code: string; }; daily: { time: string[]; weather_code: number[]; }; } // Follow WMO Weather interpretation codes (WW) const weatherCodeDisplayMap: Record< string, { icon: JSX.Element; status: string; } > = { "0": { icon: ☀️, status: "Clear sky", }, "1": { icon: 🌤️, status: "Mainly clear", }, "2": { icon: ☁️, status: "Partly cloudy", }, "3": { icon: ☁️, status: "Overcast", }, "45": { icon: 🌫️, status: "Fog", }, "48": { icon: 🌫️, status: "Depositing rime fog", }, "51": { icon: 🌧️, status: "Drizzle", }, "53": { icon: 🌧️, status: "Drizzle", }, "55": { icon: 🌧️, status: "Drizzle", }, "56": { icon: 🌧️, status: "Freezing Drizzle", }, "57": { icon: 🌧️, status: "Freezing Drizzle", }, "61": { icon: 🌧️, status: "Rain", }, "63": { icon: 🌧️, status: "Rain", }, "65": { icon: 🌧️, status: "Rain", }, "66": { icon: 🌧️, status: "Freezing Rain", }, "67": { icon: 🌧️, status: "Freezing Rain", }, "71": { icon: ❄️, status: "Snow fall", }, "73": { icon: ❄️, status: "Snow fall", }, "75": { icon: ❄️, status: "Snow fall", }, "77": { icon: ❄️, status: "Snow grains", }, "80": { icon: 🌧️, status: "Rain showers", }, "81": { icon: 🌧️, status: "Rain showers", }, "82": { icon: 🌧️, status: "Rain showers", }, "85": { icon: ❄️, status: "Snow showers", }, "86": { icon: ❄️, status: "Snow showers", }, "95": { icon: ⛈️, status: "Thunderstorm", }, "96": { icon: ⛈️, status: "Thunderstorm", }, "99": { icon: ⛈️, status: "Thunderstorm", }, }; const displayDay = (time: string) => { return new Date(time).toLocaleDateString("en-US", { weekday: "long", }); }; export function WeatherCard({ data }: { data: WeatherData }) { const currentDayString = new Date(data.current.time).toLocaleDateString( "en-US", { weekday: "long", month: "long", day: "numeric", }, ); return (
{currentDayString}
{data.current.temperature_2m} {data.current_units.temperature_2m} {weatherCodeDisplayMap[data.current.weather_code].icon}
{weatherCodeDisplayMap[data.current.weather_code].status}
{data.daily.time.map((time, index) => { if (index === 0) return null; // skip the current day return (
{displayDay(time)}
{weatherCodeDisplayMap[data.daily.weather_code[index]].icon}
{weatherCodeDisplayMap[data.daily.weather_code[index]].status}
); })}
); }