import useSWR from "swr"; import { BiError } from "react-icons/bi"; import { useTranslation } from "react-i18next"; import Icon from "./icon"; export default function OpenWeatherMap({ options }) { const { t, i18n } = useTranslation(); const { data, error } = useSWR( `/api/widgets/openweathermap?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}` ); if (error || data?.cod === 401) { return (
API Error
); } if (!data) { return
; } if (data.error) { return
; } const unit = options.units === "metric" ? "celsius" : "fahrenheit"; return (
data.sys.sunrise && data.dt < data.sys.sundown ? "day" : "night"} />
{options.label && `${options.label}, `} {t("common.number", { value: data.main.temp, style: "unit", unit })} {data.weather[0].description}
); }