mirror of
https://github.com/karl0ss/homepage.git
synced 2025-04-29 12:03:41 +01:00
add greeting and datetime info widgets
This commit is contained in:
parent
43f7ccd166
commit
0075429e08
@ -2,6 +2,8 @@ import WeatherApi from "components/widgets/weather/weather";
|
|||||||
import OpenWeatherMap from "components/widgets/openweathermap/weather";
|
import OpenWeatherMap from "components/widgets/openweathermap/weather";
|
||||||
import Resources from "components/widgets/resources/resources";
|
import Resources from "components/widgets/resources/resources";
|
||||||
import Search from "components/widgets/search/search";
|
import Search from "components/widgets/search/search";
|
||||||
|
import Greeting from "components/widgets/greeting/greeting";
|
||||||
|
import DateTime from "components/widgets/datetime/datetime";
|
||||||
|
|
||||||
const widgetMappings = {
|
const widgetMappings = {
|
||||||
weather: WeatherApi, // This key will be deprecated in the future
|
weather: WeatherApi, // This key will be deprecated in the future
|
||||||
@ -9,13 +11,15 @@ const widgetMappings = {
|
|||||||
openweathermap: OpenWeatherMap,
|
openweathermap: OpenWeatherMap,
|
||||||
resources: Resources,
|
resources: Resources,
|
||||||
search: Search,
|
search: Search,
|
||||||
|
greeting: Greeting,
|
||||||
|
datetime: DateTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Widget({ widget }) {
|
export default function Widget({ widget }) {
|
||||||
const ServiceWidget = widgetMappings[widget.type];
|
const InfoWidget = widgetMappings[widget.type];
|
||||||
|
|
||||||
if (ServiceWidget) {
|
if (InfoWidget) {
|
||||||
return <ServiceWidget options={widget.options} />;
|
return <InfoWidget options={widget.options} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
36
src/components/widgets/datetime/datetime.jsx
Normal file
36
src/components/widgets/datetime/datetime.jsx
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
const textSizes = {
|
||||||
|
"4xl": "text-4xl",
|
||||||
|
"3xl": "text-3xl",
|
||||||
|
"2xl": "text-2xl",
|
||||||
|
xl: "text-xl",
|
||||||
|
lg: "text-lg",
|
||||||
|
md: "text-md",
|
||||||
|
sm: "text-sm",
|
||||||
|
xs: "text-xs",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function DateTime({ options }) {
|
||||||
|
const { text_size: textSize, format } = options;
|
||||||
|
const { i18n } = useTranslation();
|
||||||
|
const [date, setDate] = useState(new Date());
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
setDate(new Date());
|
||||||
|
}, 1000);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, [setDate]);
|
||||||
|
|
||||||
|
const dateFormat = new Intl.DateTimeFormat(i18n.language, { ...format });
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-row items-center grow justify-end">
|
||||||
|
<span className={`text-theme-800 dark:text-theme-200 ${textSizes[textSize || "lg"]}`}>
|
||||||
|
{dateFormat.format(date)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
22
src/components/widgets/greeting/greeting.jsx
Normal file
22
src/components/widgets/greeting/greeting.jsx
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
const textSizes = {
|
||||||
|
"4xl": "text-4xl",
|
||||||
|
"3xl": "text-3xl",
|
||||||
|
"2xl": "text-2xl",
|
||||||
|
xl: "text-xl",
|
||||||
|
lg: "text-lg",
|
||||||
|
md: "text-md",
|
||||||
|
sm: "text-sm",
|
||||||
|
xs: "text-xs",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function Greeting({ options }) {
|
||||||
|
if (options.text) {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-row items-center justify-start">
|
||||||
|
<span className={`text-theme-800 dark:text-theme-200 ${textSizes[options.text_size || "xl"]}`}>
|
||||||
|
{options.text}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,7 @@ const ColorToggle = dynamic(() => import("components/color-toggle"), {
|
|||||||
ssr: false,
|
ssr: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const rightAlignedWidgets = ["weatherapi", "openweathermap", "weather", "search"];
|
const rightAlignedWidgets = ["weatherapi", "openweathermap", "weather", "search", "datetime"];
|
||||||
|
|
||||||
export async function getStaticProps() {
|
export async function getStaticProps() {
|
||||||
const settings = await getSettings();
|
const settings = await getSettings();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user