|
|
@ -1,9 +1,11 @@
|
|
|
|
import useSWR from "swr";
|
|
|
|
import useSWR from "swr";
|
|
|
|
import { useState } from "react";
|
|
|
|
import { useState } from "react";
|
|
|
|
import { BiError } from "react-icons/bi";
|
|
|
|
|
|
|
|
import { WiCloudDown } from "react-icons/wi";
|
|
|
|
import { WiCloudDown } from "react-icons/wi";
|
|
|
|
import { MdLocationDisabled, MdLocationSearching } from "react-icons/md";
|
|
|
|
import { MdLocationDisabled, MdLocationSearching } from "react-icons/md";
|
|
|
|
import { useTranslation } from "next-i18next";
|
|
|
|
import { useTranslation } from "next-i18next";
|
|
|
|
|
|
|
|
import classNames from "classnames";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import Error from "../error";
|
|
|
|
|
|
|
|
|
|
|
|
import Icon from "./icon";
|
|
|
|
import Icon from "./icon";
|
|
|
|
|
|
|
|
|
|
|
@ -15,24 +17,15 @@ function Widget({ options }) {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (error || data?.error) {
|
|
|
|
if (error || data?.error) {
|
|
|
|
return (
|
|
|
|
return <Error options={options} />
|
|
|
|
<div className="flex flex-col justify-center first:ml-0 ml-4 mr-2">
|
|
|
|
|
|
|
|
<div className="flex flex-row items-center justify-end">
|
|
|
|
|
|
|
|
<div className="flex flex-col items-center">
|
|
|
|
|
|
|
|
<BiError className="w-8 h-8 text-theme-800 dark:text-theme-200" />
|
|
|
|
|
|
|
|
<div className="flex flex-col ml-3 text-left">
|
|
|
|
|
|
|
|
<span className="text-theme-800 dark:text-theme-200 text-sm">{t("widget.api_error")}</span>
|
|
|
|
|
|
|
|
<span className="text-theme-800 dark:text-theme-200 text-xs">-</span>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
if (!data) {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className="flex flex-col justify-center first:ml-0 ml-4 mr-2">
|
|
|
|
<div className={classNames(
|
|
|
|
|
|
|
|
"flex flex-col justify-center first:ml-0 ml-4 mr-2",
|
|
|
|
|
|
|
|
options?.styleBoxed === true && " ml-4 mt-2 m:mb-0 rounded-md shadow-md shadow-theme-900/10 dark:shadow-theme-900/20 bg-theme-100/20 dark:bg-white/5 p-3",
|
|
|
|
|
|
|
|
)}>
|
|
|
|
<div className="flex flex-row items-center justify-end">
|
|
|
|
<div className="flex flex-row items-center justify-end">
|
|
|
|
<div className="flex flex-col items-center">
|
|
|
|
<div className="flex flex-col items-center">
|
|
|
|
<WiCloudDown className="w-8 h-8 text-theme-800 dark:text-theme-200" />
|
|
|
|
<WiCloudDown className="w-8 h-8 text-theme-800 dark:text-theme-200" />
|
|
|
@ -50,7 +43,10 @@ function Widget({ options }) {
|
|
|
|
const timeOfDay = data.current_weather.time > data.daily.sunrise[0] && data.current_weather.time < data.daily.sunset[0] ? "day" : "night";
|
|
|
|
const timeOfDay = data.current_weather.time > data.daily.sunrise[0] && data.current_weather.time < data.daily.sunset[0] ? "day" : "night";
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className="flex flex-col justify-center first:ml-0 ml-4 mr-2">
|
|
|
|
<div className={classNames(
|
|
|
|
|
|
|
|
"flex flex-col justify-center first:ml-0 ml-4 mr-2",
|
|
|
|
|
|
|
|
options?.styleBoxed === true && " ml-4 mt-2 m:mb-0 rounded-md shadow-md shadow-theme-900/10 dark:shadow-theme-900/20 bg-theme-100/20 dark:bg-white/5 p-3",
|
|
|
|
|
|
|
|
)}>
|
|
|
|
<div className="flex flex-row items-center justify-end">
|
|
|
|
<div className="flex flex-row items-center justify-end">
|
|
|
|
<div className="flex flex-col items-center">
|
|
|
|
<div className="flex flex-col items-center">
|
|
|
|
<Icon condition={data.current_weather.weathercode} timeOfDay={timeOfDay} />
|
|
|
|
<Icon condition={data.current_weather.weathercode} timeOfDay={timeOfDay} />
|
|
|
@ -107,8 +103,10 @@ export default function OpenMeteo({ options }) {
|
|
|
|
<button
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
type="button"
|
|
|
|
onClick={() => requestLocation()}
|
|
|
|
onClick={() => requestLocation()}
|
|
|
|
className="flex flex-col justify-center first:ml-0 ml-4 mr-2"
|
|
|
|
className={classNames(
|
|
|
|
>
|
|
|
|
"flex flex-col justify-center first:ml-0 ml-4 mr-2",
|
|
|
|
|
|
|
|
options?.styleBoxed === true && " ml-4 mt-2 m:mb-0 rounded-md shadow-md shadow-theme-900/10 dark:shadow-theme-900/20 bg-theme-100/20 dark:bg-white/5 p-3",
|
|
|
|
|
|
|
|
)}>
|
|
|
|
<div className="flex flex-row items-center justify-end">
|
|
|
|
<div className="flex flex-row items-center justify-end">
|
|
|
|
<div className="flex flex-col items-center">
|
|
|
|
<div className="flex flex-col items-center">
|
|
|
|
{requesting ? (
|
|
|
|
{requesting ? (
|
|
|
|