import { Box, Group, Loader, Stack, Text } from "@mantine/core"; import { clientApi } from "@homarr/api/client"; import { useI18n, useScopedI18n } from "@homarr/translation/client"; import { isInitialWidgetQueryPending } from "../common/query-state"; import { WidgetQueryErrorIndicator } from "../common/query-state-indicator"; import { AnimatedWeatherIcon } from "../weather/animated-icon"; import { WeatherDescription } from "../weather/icon"; interface ClockWeatherSummaryProps { latitude: number; longitude: number; locationName: string; isFahrenheit: boolean; animateIcon: boolean; detailed: boolean; } export const ClockWeatherSummary = ({ latitude, longitude, locationName, isFahrenheit, animateIcon, detailed, }: ClockWeatherSummaryProps) => { const t = useI18n(); const tCommon = useScopedI18n("common"); const weatherQuery = clientApi.widget.weather.atLocation.useQuery({ latitude, longitude }); const weather = weatherQuery.data; if (!weather) { return isInitialWidgetQueryPending(weatherQuery) ? ( ) : ( ); } const temperature = isFahrenheit ? weather.current.temperature * (9 / 5) + 32 : weather.current.temperature; const unit = isFahrenheit ? "°F" : "°C"; const today = weather.daily[0]; const formatTemperature = (value: number | null | undefined) => { if (value === undefined || value === null) return "—"; const preferred = isFahrenheit ? value * (9 / 5) + 32 : value; return `${Math.round(preferred)}${unit}`; }; return ( {Math.round(temperature)} {unit} {detailed && } {detailed && ( {locationName} {formatTemperature(today?.maxTemperature)} / {formatTemperature(today?.minTemperature)} )} ); };