From 12d154832a0b425ab9bd35d7bcc0c19a00b11ba6 Mon Sep 17 00:00:00 2001 From: Neshura Date: Thu, 15 Dec 2022 21:23:54 +0100 Subject: [PATCH] Modified Theme Selector --- components/themeselector.tsx | 79 ++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 22 deletions(-) diff --git a/components/themeselector.tsx b/components/themeselector.tsx index bde1496..65acea4 100644 --- a/components/themeselector.tsx +++ b/components/themeselector.tsx @@ -1,47 +1,82 @@ import { useUpdateTheme } from "../pages/_app"; -import { useContext } from 'react'; -import { ThemeContext, DefaultTheme } from "styled-components"; -import { darkTheme, amoledTheme, lightTheme } from './themes'; +import { Fragment, useContext, useState } from 'react'; +import { ThemeContext, DefaultTheme } from "styled-components"; +import { darkTheme, amoledTheme, lightTheme, amoled2Theme } from './themes'; +import { ThemeDropDown, ThemeDropDownButton, ThemeDropDownOption, ThemeDropDownOptions } from "./styles/themedropdown"; + +const themes = [ + lightTheme, + darkTheme, + amoledTheme, + amoled2Theme, +] const StyleSelector = () => { const updateTheme = useUpdateTheme(); const currentTheme = useContext(ThemeContext); + const [selectedTheme, setSelectedTheme] = useState(themes[currentTheme.themeId]); - //console.log(currentTheme); // DEBUG + const updateThemeWithStorage = (newTheme: DefaultTheme) => { - let newTheme: DefaultTheme; - switch(currentTheme.themeId) { - case 1: - newTheme = darkTheme; - break; - case 2: - newTheme = amoledTheme; - break; - case 3: - newTheme = lightTheme; - break; - default: - newTheme = currentTheme; + if (newTheme.themeId === lightTheme.themeId) { + updateLightTheme(newTheme); + } + else { + setSelectedTheme(newTheme); + localStorage.setItem("theme", newTheme.themeId.toString()); + updateTheme(newTheme); + } } + const updateLightTheme = (newTheme: DefaultTheme) => { + if (confirm("Really switch to Light Mode?")) { + setSelectedTheme(newTheme); + localStorage.setItem("theme", newTheme.themeId.toString()); + updateTheme(newTheme) + } + else { + + } + } + + const [test, setTest] = useState(false); + return ( - + + + setTest(test => !test)}>{selectedTheme.themeName} + + {themes.map((theme) => ( + updateThemeWithStorage(theme)}> + {theme.themeName} + + ))} + + ); } +{/* + + + */} + export function getTheme(themeId: number): DefaultTheme { let theme: DefaultTheme; - switch(themeId) { - case 1: + switch (themeId) { + case 0: theme = lightTheme; break; - case 2: + case 1: theme = darkTheme; break; - case 3: + case 2: theme = amoledTheme; break; + case 3: + theme = amoled2Theme; + break; default: theme = darkTheme }