diff --git a/src/components/ThemeProvider.tsx b/src/components/ThemeProvider.tsx index 2c21bee..71b1567 100644 --- a/src/components/ThemeProvider.tsx +++ b/src/components/ThemeProvider.tsx @@ -21,13 +21,17 @@ type ThemeProviderProps = { type ThemeProviderState = { themes: Theme[]; theme: Theme; + background: string; setTheme: (theme: Theme) => void; + setBackground: (background: string) => void; }; const initialState: ThemeProviderState = { themes: themes, theme: "main", - setTheme: () => null + background: "", + setTheme: () => null, + setBackground: () => null }; const ThemeProviderContext = createContext(initialState); @@ -35,9 +39,13 @@ const ThemeProviderContext = createContext(initialState); export function ThemeProvider({ children, ...props }: ThemeProviderProps) { const defaultTheme = "main"; const storageKey = "theme"; + const bgKey = "background"; const [theme, setTheme] = useState( () => (localStorage.getItem(storageKey) as Theme) || defaultTheme ); + const [background, setBackground] = useState(() => + localStorage.getItem(bgKey) + ); useEffect(() => { const root = window.document.documentElement; @@ -45,16 +53,20 @@ export function ThemeProvider({ children, ...props }: ThemeProviderProps) { themes.forEach((theme) => { root.classList.remove(theme); }); - root.classList.add(theme); }, [theme, themes]); const value = { theme, themes, + background, setTheme: (theme: Theme) => { localStorage.setItem(storageKey, theme); setTheme(theme); + }, + setBackground: (background: string) => { + localStorage.setItem(bgKey, background); + setBackground(background); } }; diff --git a/src/index.tsx b/src/index.tsx index a8854b8..03e8377 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -6,11 +6,10 @@ import Particles, { initParticlesEngine } from "@tsparticles/react"; import { loadSlim } from "@tsparticles/slim"; import { useEffect, useState } from "preact/compat"; -import { ThemeProvider } from "./components/ThemeProvider"; +import { ThemeProvider, useTheme } from "./components/ThemeProvider"; const Routes = lazy(() => import("./routes")); -const theme = localStorage.getItem("theme") || "main"; const particlesUrl = localStorage.getItem("particles") || "none"; export default function App() { @@ -30,42 +29,44 @@ export default function App() { setInit(true); }); }, []); - + const { background } = useTheme(); const particlesLoaded = (container) => { console.log(container); }; - const bgImage: string | undefined = localStorage.getItem("background"); return ( - -
- {window.location.origin === "https://nebulaproxy.io" && } - {/* {window.location.origin === "http://localhost:8080" && } */} - }> -
- -
-
- {init && particlesUrl !== "none" && ( - - )} -
-
-
-
+
+ {window.location.origin === "https://nebulaproxy.io" && } + {/* {window.location.origin === "http://localhost:8080" && } */} + }> +
+ +
+
+ {init && particlesUrl !== "none" && ( + + )} +
+
+
); } -render(, document.getElementById("app")); +render( + + + , + document.getElementById("app") +); diff --git a/src/pages/Settings/Customization.tsx b/src/pages/Settings/Customization.tsx index b826c19..ed02e42 100644 --- a/src/pages/Settings/Customization.tsx +++ b/src/pages/Settings/Customization.tsx @@ -1,4 +1,5 @@ import { useRef } from "preact/hooks"; +import { useTheme } from "../../components/ThemeProvider"; import { motion } from "framer-motion"; import { tabContentVariant, settingsPageVariant } from "./Variants"; import { useTranslation } from "react-i18next"; @@ -8,7 +9,7 @@ import ThemeDropdown from "./ThemeDropdown"; function Customization({ id, active }) { const bgInput = useRef(null); const { t } = useTranslation(); - + const { background, setBackground } = useTheme(); const particles = [ { id: "none", label: t("settings.theme.particlesNone") }, { id: "/crismas.json", label: t("themes.crismas") } @@ -55,16 +56,11 @@ function Customization({ id, active }) {