import { useQuery } from "@tanstack/react-query"; import { Cloud, CloudRain, Sun, CloudSnow, ThermometerSun } from "lucide-react"; import { Card, CardContent } from "@/components/ui/card"; interface WeatherData { id: number; date: string; location: string; maxTemperature: number; minTemperature: number; condition: string; icon: string; isCurrentYear: boolean; createdAt: string; updatedAt: string; } interface WeatherResponse { currentYear: WeatherData | null; previousYear: WeatherData | null; location: string; } const WeatherIcon = ({ condition, size = 16 }: { condition: string; size?: number }) => { const iconClass = `h-${Math.floor(size/4)} w-${Math.floor(size/4)}`; if (condition.includes('rain') || condition.includes('pluie')) { return ; } if (condition.includes('snow') || condition.includes('neige')) { return ; } if (condition.includes('cloud') || condition.includes('nuage')) { return ; } if (condition.includes('sun') || condition.includes('soleil') || condition.includes('clear')) { return ; } return ; }; export default function WeatherWidget() { const { data: weather, isLoading, error } = useQuery({ queryKey: ['/api/weather/current'], refetchInterval: 30 * 60 * 1000, // Refetch every 30 minutes retry: 1, }); if (isLoading) { return (
Chargement météo...
); } if (error || !weather) { return null; // Don't show widget if weather service is not configured } const currentTemp = weather.currentYear?.maxTemperature; const previousTemp = weather.previousYear?.maxTemperature; const location = weather.location || "Nancy"; return (
{location.split(',')[0]}
{currentTemp !== undefined ? `${Math.round(currentTemp)}°` : '--°'}
{previousTemp !== undefined && (
(l'an dernier: {Math.round(previousTemp)}°)
)}
{currentTemp !== undefined && previousTemp !== undefined && (
{currentTemp > previousTemp ? ( ↑{Math.round(currentTemp - previousTemp)}° ) : currentTemp < previousTemp ? ( ↓{Math.round(previousTemp - currentTemp)}° ) : ( = )}
)}
); }