From 2d424655e54ffedc69e72a351b90d475c3a95b40 Mon Sep 17 00:00:00 2001 From: zv Date: Sun, 14 Jun 2026 11:05:04 +0200 Subject: [PATCH] fix: prefer hybrid cloud cover in hero --- components/weather/weather-hero.tsx | 9 ++++++++- lib/weather-utils.ts | 21 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/components/weather/weather-hero.tsx b/components/weather/weather-hero.tsx index f5b81cb..710d25e 100644 --- a/components/weather/weather-hero.tsx +++ b/components/weather/weather-hero.tsx @@ -80,7 +80,14 @@ export function WeatherHero({ station, currentWeather, currentWeatherLoading = f : devEffectOverride === "rain" || devEffectOverride === "none" ? false : currentWeather?.condition === "thunderstorm"; - const weatherDescription = getWeatherDescription(displayedStation, language, currentWeather?.condition, currentForecastWeatherCode); + const weatherDescription = getWeatherDescription( + displayedStation, + language, + currentWeather?.condition, + currentWeather?.weatherCode, + currentWeather?.cloudCover, + currentForecastWeatherCode, + ); useEffect(() => { if (process.env.NODE_ENV !== "development") return; diff --git a/lib/weather-utils.ts b/lib/weather-utils.ts index d6e156e..4a56cbf 100644 --- a/lib/weather-utils.ts +++ b/lib/weather-utils.ts @@ -249,11 +249,30 @@ function getForecastConditionDescription(code: number | null, language: Language return null; } -export function getWeatherDescription(station: SynopStation, language: Language = "pl", condition?: CurrentWeatherCondition, forecastWeatherCode?: number | null) { +function getCloudCoverDescription(cloudCover: number | null | undefined, language: Language) { + if (cloudCover === null || cloudCover === undefined) return null; + if (cloudCover >= 75) return translate(language, "forecast.condition.cloudy"); + if (cloudCover >= 25) return translate(language, "forecast.condition.partlyCloudy"); + return null; +} + +export function getWeatherDescription( + station: SynopStation, + language: Language = "pl", + condition?: CurrentWeatherCondition, + currentWeatherCode?: number | null, + currentCloudCover?: number | null, + forecastWeatherCode?: number | null, +) { if (condition === "thunderstorm") return translate(language, "weather.thunderstorm"); if (condition === "snow") return translate(language, "weather.currentSnow"); if (condition === "rain") return translate(language, "weather.currentRain"); if ((station.windSpeed ?? 0) >= 8) return translate(language, "weather.strongWind"); + const currentDescription = getForecastConditionDescription(currentWeatherCode ?? null, language); + const cloudCoverDescription = getCloudCoverDescription(currentCloudCover, language); + if (cloudCoverDescription && (currentWeatherCode === null || currentWeatherCode === undefined || currentWeatherCode === 0)) return cloudCoverDescription; + if (currentDescription) return currentDescription; + if (cloudCoverDescription) return cloudCoverDescription; const forecastDescription = getForecastConditionDescription(forecastWeatherCode ?? null, language); if (forecastDescription) return forecastDescription; if ((station.humidity ?? 0) >= 90) return translate(language, "weather.humid");