diff --git a/src/contexts/UserSettingsProvider.tsx b/src/contexts/UserSettingsProvider.tsx deleted file mode 100644 index 6f1f06b..0000000 --- a/src/contexts/UserSettingsProvider.tsx +++ /dev/null @@ -1,111 +0,0 @@ -import { atomWithStorage } from "jotai/utils"; -import { atom } from "jotai"; -import { useRouter } from "next/router"; -import { useLayoutEffect, useEffect } from "react"; -import { atomPairing, useAtomGetter, useAtomPair } from "helpers/atoms"; -import { getDefaultPreferredLanguages } from "helpers/locales"; -import { isDefined, isDefinedAndNotEmpty } from "helpers/others"; -import { usePrefersDarkMode } from "hooks/useMediaQuery"; -import { SettingsPopup } from "components/Panels/SettingsPopup"; - -export enum ThemeMode { - Dark = "dark", - Auto = "auto", - Light = "light", -} - -const preferredLanguagesAtom = atomPairing(atomWithStorage("preferredLanguages", [])); -const themeModeAtom = atomPairing(atomWithStorage("themeMode", ThemeMode.Auto)); -const darkModeAtom = atomPairing(atom(false)); -const fontSizeAtom = atomPairing(atomWithStorage("fontSize", 1)); -const dyslexicAtom = atomPairing(atomWithStorage("isDyslexic", false)); -const currencyAtom = atomPairing(atomWithStorage("currency", "USD")); -const playerNameAtom = atomPairing(atomWithStorage("playerName", "")); - -export const settings = { - preferredLanguages: preferredLanguagesAtom, - themeMode: themeModeAtom, - darkMode: darkModeAtom, - fontSize: fontSizeAtom, - dyslexic: dyslexicAtom, - currency: currencyAtom, - playerName: playerNameAtom, -}; - -export const UserSettingsProvider = ({ children }: { children: React.ReactNode }): JSX.Element => { - const router = useRouter(); - const [preferredLanguages, setPreferredLanguages] = useAtomPair(settings.preferredLanguages); - const fontSize = useAtomGetter(settings.fontSize); - const isDyslexic = useAtomGetter(settings.dyslexic); - const [isDarkMode, setDarkMode] = useAtomPair(settings.darkMode); - const themeMode = useAtomGetter(settings.themeMode); - - useLayoutEffect(() => { - const html = document.getElementsByTagName("html")[0]; - if (isDefined(html)) { - html.style.fontSize = `${fontSize * 100}%`; - } - }, [fontSize]); - - useLayoutEffect(() => { - const next = document.getElementById("__next"); - if (isDefined(next)) { - if (isDyslexic) { - next.classList.add("set-theme-font-dyslexic"); - next.classList.remove("set-theme-font-standard"); - } else { - next.classList.add("set-theme-font-standard"); - next.classList.remove("set-theme-font-dyslexic"); - } - } - }, [isDyslexic]); - - /* DARK MODE */ - const prefersDarkMode = usePrefersDarkMode(); - - useEffect(() => { - setDarkMode(themeMode === ThemeMode.Auto ? prefersDarkMode : themeMode === ThemeMode.Dark); - }, [prefersDarkMode, setDarkMode, themeMode]); - - useLayoutEffect(() => { - const next = document.getElementById("__next"); - if (isDefined(next)) { - if (isDarkMode) { - next.classList.add("set-theme-dark"); - next.classList.remove("set-theme-light"); - } else { - next.classList.add("set-theme-light"); - next.classList.remove("set-theme-dark"); - } - } - }, [isDarkMode]); - - /* PREFERRED LANGUAGES */ - - useEffect(() => { - if (preferredLanguages.length === 0) { - if (isDefinedAndNotEmpty(router.locale) && router.locales) { - setPreferredLanguages(getDefaultPreferredLanguages(router.locale, router.locales)); - } - } else if (router.locale !== preferredLanguages[0]) { - /* - * Using a timeout to the code getting stuck into a loop when reaching the website with a - * different preferredLanguages[0] from router.locale - */ - setTimeout( - async () => - router.replace(router.asPath, router.asPath, { - locale: preferredLanguages[0], - }), - 250 - ); - } - }, [preferredLanguages, router, setPreferredLanguages]); - - return ( - <> - - {children} - - ); -}; diff --git a/src/contexts/atoms.ts b/src/contexts/atoms.ts index 92059ab..03213df 100644 --- a/src/contexts/atoms.ts +++ b/src/contexts/atoms.ts @@ -60,7 +60,7 @@ export const lightBox = atomPairing( const previousLines = atomPairing(atom([])); const previousCommands = atomPairing(atom([])); -export const terminal = { +const terminal = { previousLines, previousCommands, }; diff --git a/src/contexts/settings.tsx b/src/contexts/settings.tsx deleted file mode 100644 index 178e553..0000000 --- a/src/contexts/settings.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import { atomWithStorage } from "jotai/utils"; -import { atom } from "jotai"; -import { useRouter } from "next/router"; -import { useLayoutEffect, useEffect } from "react"; -import { atomPairing, useAtomGetter, useAtomPair } from "helpers/atoms"; -import { getDefaultPreferredLanguages } from "helpers/locales"; -import { isDefined, isDefinedAndNotEmpty } from "helpers/others"; -import { usePrefersDarkMode } from "hooks/useMediaQuery"; -import { SettingsPopup } from "components/Panels/SettingsPopup"; - -export enum ThemeMode { - Dark = "dark", - Auto = "auto", - Light = "light", -} - -const preferredLanguagesAtom = atomPairing(atomWithStorage("preferredLanguages", [])); -const themeModeAtom = atomPairing(atomWithStorage("themeMode", ThemeMode.Auto)); -const darkModeAtom = atomPairing(atom(false)); -const fontSizeAtom = atomPairing(atomWithStorage("fontSize", 1)); -const dyslexicAtom = atomPairing(atomWithStorage("isDyslexic", false)); -const currencyAtom = atomPairing(atomWithStorage("currency", "USD")); -const playerNameAtom = atomPairing(atomWithStorage("playerName", "")); - -export const settings = { - preferredLanguages: preferredLanguagesAtom, - themeMode: themeModeAtom, - darkMode: darkModeAtom, - fontSize: fontSizeAtom, - dyslexic: dyslexicAtom, - currency: currencyAtom, - playerName: playerNameAtom, -}; \ No newline at end of file diff --git a/src/pages/archives/videos/c/[uid].tsx b/src/pages/archives/videos/c/[uid].tsx index 58fa760..41e0709 100644 --- a/src/pages/archives/videos/c/[uid].tsx +++ b/src/pages/archives/videos/c/[uid].tsx @@ -49,7 +49,6 @@ const Channel = ({ channel, ...otherProps }: Props): JSX.Element => { const hoverable = useDeviceSupportsHover(); const isContentPanelAtLeast4xl = useAtomGetter(atoms.containerQueries.isContentPanelAtLeast4xl); - const [searchName, setSearchName] = useState(DEFAULT_FILTERS_STATE.searchName); const subPanel = useMemo( diff --git a/src/pages/contents/all.tsx b/src/pages/contents/all.tsx index f7e3641..1525854 100644 --- a/src/pages/contents/all.tsx +++ b/src/pages/contents/all.tsx @@ -53,7 +53,6 @@ const Contents = ({ contents, ...otherProps }: Props): JSX.Element => { const langui = useAtomGetter(atoms.localData.langui); const isContentPanelAtLeast4xl = useAtomGetter(atoms.containerQueries.isContentPanelAtLeast4xl); - const [groupingMethod, setGroupingMethod] = useState( DEFAULT_FILTERS_STATE.groupingMethod ); diff --git a/src/pages/contents/folder/[slug].tsx b/src/pages/contents/folder/[slug].tsx index a0b2007..4eea4f0 100644 --- a/src/pages/contents/folder/[slug].tsx +++ b/src/pages/contents/folder/[slug].tsx @@ -37,7 +37,6 @@ const ContentsFolder = ({ openGraph, folder, ...otherProps }: Props): JSX.Elemen const langui = useAtomGetter(atoms.localData.langui); const isContentPanelAtLeast4xl = useAtomGetter(atoms.containerQueries.isContentPanelAtLeast4xl); - const subPanel = useMemo( () => ( diff --git a/src/types/types.ts b/src/types/types.ts index 62c91df..18fcb97 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -45,12 +45,6 @@ export interface ChronicleWithTranslations extends Omit = { - [P in keyof T]-?: NonNullable; -}; - -// ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ - export enum LibraryItemUserStatus { None = 0, Want = 1,