mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-10 15:28:47 +00:00
first public source commit
This commit is contained in:
parent
1a4fbb9d42
commit
3914fee775
65 changed files with 4697 additions and 312 deletions
9
src/components/widgets/weather/icon.jsx
Normal file
9
src/components/widgets/weather/icon.jsx
Normal file
|
@ -0,0 +1,9 @@
|
|||
import mapIcon from "utils/condition-map";
|
||||
|
||||
export default function Icon({ condition, timeOfDay }) {
|
||||
const Icon = mapIcon(condition, timeOfDay);
|
||||
|
||||
return (
|
||||
<Icon className="mt-2 w-10 h-10 text-theme-800 dark:text-theme-200"></Icon>
|
||||
);
|
||||
}
|
41
src/components/widgets/weather/weather.jsx
Normal file
41
src/components/widgets/weather/weather.jsx
Normal file
|
@ -0,0 +1,41 @@
|
|||
import useSWR from "swr";
|
||||
import Icon from "./icon";
|
||||
|
||||
export default function Weather({ options }) {
|
||||
const { data, error } = useSWR(
|
||||
`/api/widgets/weather?lat=${options.latitude}&lon=${options.longitude}&apiKey=${options.apiKey}&duration=${options.cache}`,
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
revalidateOnReconnect: false,
|
||||
}
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return <div>failed to load</div>;
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return <div className="flex flex-col items-center justify-center"></div>;
|
||||
}
|
||||
|
||||
if (data.error) {
|
||||
return <div className="flex flex-col items-center justify-center"></div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="order-last grow flex-none flex flex-row items-center justify-end">
|
||||
<Icon
|
||||
condition={data.current.condition.code}
|
||||
timeOfDay={data.current.is_day ? "day" : "night"}
|
||||
/>
|
||||
<div className="flex flex-col ml-3 text-left">
|
||||
<span className="text-theme-800 dark:text-theme-200 text-sm">
|
||||
{Math.round(data.current.temp_f)}°
|
||||
</span>
|
||||
<span className="text-theme-800 dark:text-theme-200 text-xs">
|
||||
{data.current.condition.text}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue