mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-12 16:08:48 +00:00
Merge branch 'main' into fix/icon
This commit is contained in:
commit
d76a18565c
141 changed files with 7378 additions and 551 deletions
|
@ -1,6 +1,7 @@
|
|||
/* eslint-disable react/jsx-props-no-spreading */
|
||||
import { SWRConfig } from "swr";
|
||||
import { appWithTranslation } from "next-i18next";
|
||||
import Head from "next/head";
|
||||
|
||||
import "styles/globals.css";
|
||||
import "styles/theme.css";
|
||||
|
@ -18,6 +19,10 @@ function MyApp({ Component, pageProps }) {
|
|||
fetcher: (resource, init) => fetch(resource, init).then((res) => res.json()),
|
||||
}}
|
||||
>
|
||||
<Head>
|
||||
{/* https://nextjs.org/docs/messages/no-document-viewport-meta */}
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||
</Head>
|
||||
<ColorProvider>
|
||||
<ThemeProvider>
|
||||
<SettingsProvider>
|
||||
|
|
|
@ -46,7 +46,7 @@ export default async function handler(req, res) {
|
|||
});
|
||||
} catch {
|
||||
res.status(500).send({
|
||||
error: "unknown error",
|
||||
error: {message: "Unknown error"},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
8
src/pages/api/widgets/openmeteo.js
Normal file
8
src/pages/api/widgets/openmeteo.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
import cachedFetch from "utils/proxy/cached-fetch";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { latitude, longitude, units, cache } = req.query;
|
||||
const degrees = units === "imperial" ? "fahrenheit" : "celsius";
|
||||
const apiUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&daily=sunrise,sunset¤t_weather=true&temperature_unit=${degrees}&timezone=auto`;
|
||||
return res.send(await cachedFetch(apiUrl, cache));
|
||||
}
|
|
@ -21,6 +21,7 @@ import { SettingsContext } from "utils/contexts/settings";
|
|||
import { bookmarksResponse, servicesResponse, widgetsResponse } from "utils/config/api-response";
|
||||
import ErrorBoundary from "components/errorboundry";
|
||||
import themes from "utils/styles/themes";
|
||||
import QuickLaunch from "components/quicklaunch";
|
||||
|
||||
const ThemeToggle = dynamic(() => import("components/toggles/theme"), {
|
||||
ssr: false,
|
||||
|
@ -34,7 +35,7 @@ const Version = dynamic(() => import("components/version"), {
|
|||
ssr: false,
|
||||
});
|
||||
|
||||
const rightAlignedWidgets = ["weatherapi", "openweathermap", "weather", "search", "datetime"];
|
||||
const rightAlignedWidgets = ["weatherapi", "openweathermap", "weather", "openmeteo", "search", "datetime"];
|
||||
|
||||
export async function getStaticProps() {
|
||||
let logger;
|
||||
|
@ -173,6 +174,8 @@ function Home({ initialSettings }) {
|
|||
const { data: services } = useSWR("/api/services");
|
||||
const { data: bookmarks } = useSWR("/api/bookmarks");
|
||||
const { data: widgets } = useSWR("/api/widgets");
|
||||
|
||||
const servicesAndBookmarks = [...services.map(sg => sg.services).flat(), ...bookmarks.map(bg => bg.bookmarks).flat()]
|
||||
|
||||
useEffect(() => {
|
||||
if (settings.language) {
|
||||
|
@ -188,6 +191,28 @@ function Home({ initialSettings }) {
|
|||
}
|
||||
}, [i18n, settings, color, setColor, theme, setTheme]);
|
||||
|
||||
const [searching, setSearching] = useState(false);
|
||||
const [searchString, setSearchString] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
function handleKeyDown(e) {
|
||||
if (e.target.tagName === "BODY") {
|
||||
if (String.fromCharCode(e.keyCode).match(/(\w|\s)/g) && !(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) {
|
||||
setSearching(true);
|
||||
} else if (e.key === "Escape") {
|
||||
setSearchString("");
|
||||
setSearching(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', handleKeyDown);
|
||||
|
||||
return function cleanup() {
|
||||
document.removeEventListener('keydown', handleKeyDown);
|
||||
}
|
||||
})
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
|
@ -219,6 +244,14 @@ function Home({ initialSettings }) {
|
|||
headerStyles[initialSettings.headerStyle || "underlined"]
|
||||
)}
|
||||
>
|
||||
<QuickLaunch
|
||||
servicesAndBookmarks={servicesAndBookmarks}
|
||||
searchString={searchString}
|
||||
setSearchString={setSearchString}
|
||||
isOpen={searching}
|
||||
close={setSearching}
|
||||
searchDescriptions={settings.quicklaunch?.searchDescriptions}
|
||||
/>
|
||||
{widgets && (
|
||||
<>
|
||||
{widgets
|
||||
|
@ -247,7 +280,7 @@ function Home({ initialSettings }) {
|
|||
)}
|
||||
|
||||
{bookmarks && (
|
||||
<div className="grow flex flex-wrap pt-0 p-4 sm:p-8">
|
||||
<div className={`grow flex flex-wrap pt-0 p-4 sm:p-8 gap-2 grid-cols-1 lg:grid-cols-2 lg:grid-cols-${Math.min(6, bookmarks.length)}`}>
|
||||
{bookmarks.map((group) => (
|
||||
<BookmarksGroup key={group.name} group={group} />
|
||||
))}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue