From 663f50d5346018088536991635df56dc66ad38e0 Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Fri, 15 Aug 2025 11:43:33 +0000 Subject: [PATCH] Update weather data to show accurate local conditions Ensure weather data is refreshed when location changes by invalidating and refetching queries on the client, and clearing the weather cache on the server. Replit-Commit-Author: Agent Replit-Commit-Session-Id: d43bd811-9372-45a7-8ac9-4a954c0538e1 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/d43bd811-9372-45a7-8ac9-4a954c0538e1/zoZabWF --- client/src/components/WeatherWidget.tsx | 3 ++- server/routes.ts | 3 +++ server/storage.ts | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/client/src/components/WeatherWidget.tsx b/client/src/components/WeatherWidget.tsx index 60288d4..cf226b9 100644 --- a/client/src/components/WeatherWidget.tsx +++ b/client/src/components/WeatherWidget.tsx @@ -154,8 +154,9 @@ export default function WeatherWidget() { description: data.message, }); - // Actualiser les données météo + // Forcer le rechargement immédiat des données météo queryClient.invalidateQueries({ queryKey: ['/api/weather/current'] }); + queryClient.refetchQueries({ queryKey: ['/api/weather/current'] }); }, onError: (error: any) => { toast({ diff --git a/server/routes.ts b/server/routes.ts index 4e2958e..4ee8a17 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -2970,6 +2970,9 @@ RÉSUMÉ DU SCAN location: locationData.fullLocation }); + // Vider le cache météo car la localisation a changé + await storage.clearWeatherCache(); + console.log('🌍 Localisation mise à jour automatiquement:', { from: settings.location, to: locationData.fullLocation, diff --git a/server/storage.ts b/server/storage.ts index 329b59c..8440673 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -202,6 +202,7 @@ export interface IStorage { createWeatherData(data: InsertWeatherData): Promise; updateWeatherData(id: number, data: Partial): Promise; deleteOldWeatherData(daysToKeep: number): Promise; + clearWeatherCache(): Promise; } export class DatabaseStorage implements IStorage { @@ -1840,6 +1841,11 @@ export class DatabaseStorage implements IStorage { console.log(`🧹 Deleted weather data older than ${daysToKeep} days`); } + + async clearWeatherCache(): Promise { + await db.delete(weatherData); + console.log('🧹 Weather cache cleared due to location change'); + } } // MemStorage class for development @@ -3261,6 +3267,11 @@ export class MemStorage implements IStorage { // In development, this is a no-op console.log(`🧹 DEV: Would delete weather data older than ${daysToKeep} days`); } + + async clearWeatherCache(): Promise { + // In development, this is a no-op + console.log('🧹 DEV: Weather cache cleared due to location change'); + } } // Use MemStorage in development, DatabaseStorage in production