feat: describe current sky in weather hero
This commit is contained in:
@@ -12,7 +12,9 @@ import { ErrorState } from "@/components/states/error-state";
|
|||||||
import { useI18n } from "@/lib/i18n";
|
import { useI18n } from "@/lib/i18n";
|
||||||
import { useMeteoStationPositions } from "@/hooks/use-meteo-stations";
|
import { useMeteoStationPositions } from "@/hooks/use-meteo-stations";
|
||||||
import { useCurrentWeather } from "@/hooks/use-current-weather";
|
import { useCurrentWeather } from "@/hooks/use-current-weather";
|
||||||
|
import { useForecast } from "@/hooks/use-forecast";
|
||||||
import { ForecastPanel } from "@/components/forecast/forecast-panel";
|
import { ForecastPanel } from "@/components/forecast/forecast-panel";
|
||||||
|
import { getUpcomingHourlyForecast } from "@/lib/forecast-utils";
|
||||||
import { locateSynopStations } from "@/lib/location-utils";
|
import { locateSynopStations } from "@/lib/location-utils";
|
||||||
import { DashboardWarnings } from "@/components/warnings/dashboard-warnings";
|
import { DashboardWarnings } from "@/components/warnings/dashboard-warnings";
|
||||||
import { WeatherBriefCard } from "@/components/dashboard/weather-brief-card";
|
import { WeatherBriefCard } from "@/components/dashboard/weather-brief-card";
|
||||||
@@ -35,6 +37,8 @@ export function DashboardPage() {
|
|||||||
const forecastLongitude = hasActiveLocationCoordinates ? activeLocation?.longitude : stationPosition?.longitude;
|
const forecastLongitude = hasActiveLocationCoordinates ? activeLocation?.longitude : stationPosition?.longitude;
|
||||||
const forecastLocationName = hasActiveLocationCoordinates ? activeLocation?.name ?? selectedStation?.name : selectedStation?.name;
|
const forecastLocationName = hasActiveLocationCoordinates ? activeLocation?.name ?? selectedStation?.name : selectedStation?.name;
|
||||||
const { data: currentWeather, isPending: isCurrentWeatherPending } = useCurrentWeather(forecastLatitude, forecastLongitude);
|
const { data: currentWeather, isPending: isCurrentWeatherPending } = useCurrentWeather(forecastLatitude, forecastLongitude);
|
||||||
|
const { data: forecast } = useForecast(forecastLatitude, forecastLongitude);
|
||||||
|
const currentForecastWeatherCode = forecast ? getUpcomingHourlyForecast(forecast.hourly, 1)[0]?.weatherCode ?? null : null;
|
||||||
const isCurrentWeatherLoading = Number.isFinite(forecastLatitude) && Number.isFinite(forecastLongitude) && isCurrentWeatherPending;
|
const isCurrentWeatherLoading = Number.isFinite(forecastLatitude) && Number.isFinite(forecastLongitude) && isCurrentWeatherPending;
|
||||||
if (isPending) return <PageLoadingSkeleton />;
|
if (isPending) return <PageLoadingSkeleton />;
|
||||||
if (isError || !stations?.length || !selectedStation) return <ErrorState onRetry={() => refetch()} description={t("dashboard.error")} />;
|
if (isError || !stations?.length || !selectedStation) return <ErrorState onRetry={() => refetch()} description={t("dashboard.error")} />;
|
||||||
@@ -42,7 +46,7 @@ export function DashboardPage() {
|
|||||||
return (
|
return (
|
||||||
<div className="space-y-10">
|
<div className="space-y-10">
|
||||||
<LocationSearch stations={stations} positions={positions} />
|
<LocationSearch stations={stations} positions={positions} />
|
||||||
<WeatherHero station={selectedStation} currentWeather={currentWeather} currentWeatherLoading={isCurrentWeatherLoading} locationName={activeLocation?.name} distanceKm={activeLocation?.distanceKm} />
|
<WeatherHero station={selectedStation} currentWeather={currentWeather} currentWeatherLoading={isCurrentWeatherLoading} currentForecastWeatherCode={currentForecastWeatherCode} locationName={activeLocation?.name} distanceKm={activeLocation?.distanceKm} />
|
||||||
<DashboardWarnings />
|
<DashboardWarnings />
|
||||||
<WeatherBriefCard latitude={forecastLatitude} longitude={forecastLongitude} locationName={forecastLocationName ?? selectedStation.name} />
|
<WeatherBriefCard latitude={forecastLatitude} longitude={forecastLongitude} locationName={forecastLocationName ?? selectedStation.name} />
|
||||||
<ForecastPanel latitude={forecastLatitude} longitude={forecastLongitude} locationName={forecastLocationName ?? selectedStation.name} />
|
<ForecastPanel latitude={forecastLatitude} longitude={forecastLongitude} locationName={forecastLocationName ?? selectedStation.name} />
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ function readDevWeatherEffectOverride(): DevWeatherEffectOverride | null {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function WeatherHero({ station, currentWeather, currentWeatherLoading = false, locationName, distanceKm }: { station: SynopStation; currentWeather?: ImgwCurrentWeather | null; currentWeatherLoading?: boolean; locationName?: string; distanceKm?: number }) {
|
export function WeatherHero({ station, currentWeather, currentWeatherLoading = false, currentForecastWeatherCode, locationName, distanceKm }: { station: SynopStation; currentWeather?: ImgwCurrentWeather | null; currentWeatherLoading?: boolean; currentForecastWeatherCode?: number | null; locationName?: string; distanceKm?: number }) {
|
||||||
const { language, t } = useI18n();
|
const { language, t } = useI18n();
|
||||||
const temperatureUnit = useWeatherStore((state) => state.temperatureUnit);
|
const temperatureUnit = useWeatherStore((state) => state.temperatureUnit);
|
||||||
const windSpeedUnit = useWeatherStore((state) => state.windSpeedUnit);
|
const windSpeedUnit = useWeatherStore((state) => state.windSpeedUnit);
|
||||||
@@ -80,6 +80,7 @@ export function WeatherHero({ station, currentWeather, currentWeatherLoading = f
|
|||||||
: devEffectOverride === "rain" || devEffectOverride === "none"
|
: devEffectOverride === "rain" || devEffectOverride === "none"
|
||||||
? false
|
? false
|
||||||
: currentWeather?.condition === "thunderstorm";
|
: currentWeather?.condition === "thunderstorm";
|
||||||
|
const weatherDescription = getWeatherDescription(displayedStation, language, currentWeather?.condition, currentForecastWeatherCode);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (process.env.NODE_ENV !== "development") return;
|
if (process.env.NODE_ENV !== "development") return;
|
||||||
@@ -102,7 +103,7 @@ export function WeatherHero({ station, currentWeather, currentWeatherLoading = f
|
|||||||
<div className="flex flex-wrap items-center gap-2">
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
<span className="flex items-center gap-1.5 text-sm font-medium text-muted"><MapPin className="size-4" />{displayedLocationName}</span>
|
<span className="flex items-center gap-1.5 text-sm font-medium text-muted"><MapPin className="size-4" />{displayedLocationName}</span>
|
||||||
<span className={`rounded-control border px-2.5 py-1 text-[0.68rem] font-semibold uppercase tracking-[0.14em] ${moodAccent}`}>
|
<span className={`rounded-control border px-2.5 py-1 text-[0.68rem] font-semibold uppercase tracking-[0.14em] ${moodAccent}`}>
|
||||||
{getWeatherDescription(displayedStation, language, currentWeather?.condition)}
|
{weatherDescription}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-2 space-y-1 text-xs text-muted">
|
<div className="mt-2 space-y-1 text-xs text-muted">
|
||||||
@@ -124,7 +125,7 @@ export function WeatherHero({ station, currentWeather, currentWeatherLoading = f
|
|||||||
<div className="text-[5.8rem] font-semibold leading-[0.85] tracking-[-0.1em] sm:text-[8rem]">
|
<div className="text-[5.8rem] font-semibold leading-[0.85] tracking-[-0.1em] sm:text-[8rem]">
|
||||||
{formatTemperature(displayedStation.temperature, language, temperatureUnit)}
|
{formatTemperature(displayedStation.temperature, language, temperatureUnit)}
|
||||||
</div>
|
</div>
|
||||||
<p className="mt-5 text-xl font-medium tracking-tight sm:text-2xl">{getWeatherDescription(displayedStation, language, currentWeather?.condition)}</p>
|
<p className="mt-5 text-xl font-medium tracking-tight sm:text-2xl">{weatherDescription}</p>
|
||||||
<p className="mt-1 text-sm text-muted">{t("weather.feelsLike")} {formatTemperature(feelsLike, language, temperatureUnit)} · {t("weather.measurement")} {formatDateTime(displayedStation.measuredAt, language)}</p>
|
<p className="mt-1 text-sm text-muted">{t("weather.feelsLike")} {formatTemperature(feelsLike, language, temperatureUnit)} · {t("weather.measurement")} {formatDateTime(displayedStation.measuredAt, language)}</p>
|
||||||
</div>
|
</div>
|
||||||
<WeatherIcon mood={mood} condition={currentWeather?.condition} className="mb-4 size-20 text-accent sm:size-28" />
|
<WeatherIcon mood={mood} condition={currentWeather?.condition} className="mb-4 size-20 text-accent sm:size-28" />
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ const translations = {
|
|||||||
"weather.feelsLike": "Odczuwalna",
|
"weather.feelsLike": "Odczuwalna",
|
||||||
"weather.measurement": "pomiar",
|
"weather.measurement": "pomiar",
|
||||||
"weather.windDirection": "Kierunek wiatru",
|
"weather.windDirection": "Kierunek wiatru",
|
||||||
"weather.calm": "Spokojne warunki",
|
"weather.calm": "Pogodnie",
|
||||||
"weather.humid": "Wilgotno",
|
"weather.humid": "Wilgotno",
|
||||||
"weather.strongWind": "Silny wiatr",
|
"weather.strongWind": "Silny wiatr",
|
||||||
"weather.currentRain": "Opady deszczu",
|
"weather.currentRain": "Opady deszczu",
|
||||||
@@ -380,7 +380,7 @@ const translations = {
|
|||||||
"weather.feelsLike": "Feels like",
|
"weather.feelsLike": "Feels like",
|
||||||
"weather.measurement": "measurement",
|
"weather.measurement": "measurement",
|
||||||
"weather.windDirection": "Wind direction",
|
"weather.windDirection": "Wind direction",
|
||||||
"weather.calm": "Calm conditions",
|
"weather.calm": "Fair",
|
||||||
"weather.humid": "Humid",
|
"weather.humid": "Humid",
|
||||||
"weather.strongWind": "Strong wind",
|
"weather.strongWind": "Strong wind",
|
||||||
"weather.currentRain": "Rain",
|
"weather.currentRain": "Rain",
|
||||||
|
|||||||
@@ -237,11 +237,25 @@ export function getWeatherMoodFromData(station: SynopStation, date = new Date())
|
|||||||
return "mild";
|
return "mild";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getWeatherDescription(station: SynopStation, language: Language = "pl", condition?: CurrentWeatherCondition) {
|
function getForecastConditionDescription(code: number | null, language: Language) {
|
||||||
|
if (code === 0) return translate(language, "forecast.condition.clear");
|
||||||
|
if (code === 1 || code === 2) return translate(language, "forecast.condition.partlyCloudy");
|
||||||
|
if (code === 3) return translate(language, "forecast.condition.cloudy");
|
||||||
|
if (code === 45 || code === 48) return translate(language, "forecast.condition.fog");
|
||||||
|
if (code !== null && code >= 51 && code <= 57) return translate(language, "forecast.condition.drizzle");
|
||||||
|
if (code !== null && ((code >= 61 && code <= 67) || (code >= 80 && code <= 82))) return translate(language, "forecast.condition.rain");
|
||||||
|
if (code !== null && ((code >= 71 && code <= 77) || code === 85 || code === 86)) return translate(language, "forecast.condition.snow");
|
||||||
|
if (code !== null && code >= 95) return translate(language, "forecast.condition.thunderstorm");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getWeatherDescription(station: SynopStation, language: Language = "pl", condition?: CurrentWeatherCondition, forecastWeatherCode?: number | null) {
|
||||||
if (condition === "thunderstorm") return translate(language, "weather.thunderstorm");
|
if (condition === "thunderstorm") return translate(language, "weather.thunderstorm");
|
||||||
if (condition === "snow") return translate(language, "weather.currentSnow");
|
if (condition === "snow") return translate(language, "weather.currentSnow");
|
||||||
if (condition === "rain") return translate(language, "weather.currentRain");
|
if (condition === "rain") return translate(language, "weather.currentRain");
|
||||||
if ((station.windSpeed ?? 0) >= 8) return translate(language, "weather.strongWind");
|
if ((station.windSpeed ?? 0) >= 8) return translate(language, "weather.strongWind");
|
||||||
|
const forecastDescription = getForecastConditionDescription(forecastWeatherCode ?? null, language);
|
||||||
|
if (forecastDescription) return forecastDescription;
|
||||||
if ((station.humidity ?? 0) >= 90) return translate(language, "weather.humid");
|
if ((station.humidity ?? 0) >= 90) return translate(language, "weather.humid");
|
||||||
return translate(language, "weather.calm");
|
return translate(language, "weather.calm");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user