mirror of
https://github.com/Dvorinka/Dash.git
synced 2026-06-04 07:22:56 +00:00
17a579880f
Relocate frontend source code from `next-app/` to `frontend/` to align with the new project structure. This includes removing the old Next.js boilerplate files and establishing a cleaner workspace. Additionally, updates the OpenAPI specification to include support for the `immich` widget type and its corresponding configuration schema. - Move frontend files to `frontend/` - Delete obsolete `next-app/` directory and its configuration - Add `immich` widget type to `openapi.yaml` - Update `FrontendPlan.md` with dashboard refactor and UX direction
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
"use client";
|
|
|
|
import { useState, useEffect } from "react";
|
|
import { QueryClientProvider } from "@tanstack/react-query";
|
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
|
import { getQueryClient } from "@/lib/api/query-client";
|
|
import { Theme, getStoredTheme, setStoredTheme, applyTheme } from "@/lib/theme/themes";
|
|
|
|
export function Providers({ children }: { children: React.ReactNode }) {
|
|
const queryClient = getQueryClient();
|
|
const [theme, setTheme] = useState<Theme>("dark");
|
|
const [mswReady, setMswReady] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const stored = getStoredTheme();
|
|
setTheme(stored);
|
|
applyTheme(stored);
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (process.env.NODE_ENV === "development" && process.env.NEXT_PUBLIC_API_BASE_URL === undefined) {
|
|
import("@/lib/mocks/browser").then(({ installMocks }) => {
|
|
installMocks();
|
|
setMswReady(true);
|
|
});
|
|
} else {
|
|
setMswReady(true);
|
|
}
|
|
}, []);
|
|
|
|
const changeTheme = (t: Theme) => {
|
|
setTheme(t);
|
|
setStoredTheme(t);
|
|
applyTheme(t);
|
|
};
|
|
|
|
if (!mswReady) {
|
|
return (
|
|
<div className="flex h-screen items-center justify-center bg-background text-foreground">
|
|
<span className="font-mono text-xs">[LOADING...]</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<QueryClientProvider client={queryClient}>
|
|
<TooltipProvider delayDuration={300}>
|
|
<ThemeContext.Provider value={{ theme, setTheme: changeTheme }}>
|
|
{children}
|
|
</ThemeContext.Provider>
|
|
</TooltipProvider>
|
|
</QueryClientProvider>
|
|
);
|
|
}
|
|
|
|
import { createContext, useContext } from "react";
|
|
|
|
type ThemeContextType = { theme: Theme; setTheme: (t: Theme) => void };
|
|
export const ThemeContext = createContext<ThemeContextType>({ theme: "dark", setTheme: () => {} });
|
|
export function useTheme() {
|
|
return useContext(ThemeContext);
|
|
}
|