mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-14 07:35:06 +01:00
Fix theme preview not being reset after leaving settings
This commit is contained in:
parent
247362a4a9
commit
3522f6c038
@ -9,6 +9,7 @@ import {
|
|||||||
} from "react";
|
} from "react";
|
||||||
|
|
||||||
import { SubtitleStyling } from "@/stores/subtitles";
|
import { SubtitleStyling } from "@/stores/subtitles";
|
||||||
|
import { usePreviewThemeStore } from "@/stores/theme";
|
||||||
|
|
||||||
export function useDerived<T>(
|
export function useDerived<T>(
|
||||||
initial: T,
|
initial: T,
|
||||||
@ -56,6 +57,11 @@ export function useSettingsState(
|
|||||||
const [backendUrlState, setBackendUrl, resetBackendUrl, backendUrlChanged] =
|
const [backendUrlState, setBackendUrl, resetBackendUrl, backendUrlChanged] =
|
||||||
useDerived(backendUrl);
|
useDerived(backendUrl);
|
||||||
const [themeState, setTheme, resetTheme, themeChanged] = useDerived(theme);
|
const [themeState, setTheme, resetTheme, themeChanged] = useDerived(theme);
|
||||||
|
const setPreviewTheme = usePreviewThemeStore((s) => s.setPreviewTheme);
|
||||||
|
const resetPreviewTheme = useCallback(
|
||||||
|
() => setPreviewTheme(theme),
|
||||||
|
[setPreviewTheme, theme],
|
||||||
|
);
|
||||||
const [
|
const [
|
||||||
appLanguageState,
|
appLanguageState,
|
||||||
setAppLanguage,
|
setAppLanguage,
|
||||||
@ -81,6 +87,7 @@ export function useSettingsState(
|
|||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
resetTheme();
|
resetTheme();
|
||||||
|
resetPreviewTheme();
|
||||||
resetAppLanguage();
|
resetAppLanguage();
|
||||||
resetSubStyling();
|
resetSubStyling();
|
||||||
resetProxyUrls();
|
resetProxyUrls();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { useCallback, useEffect, useMemo } from "react";
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useAsyncFn } from "react-use";
|
import { useAsyncFn } from "react-use";
|
||||||
|
|
||||||
@ -105,6 +105,8 @@ export function SettingsPage() {
|
|||||||
const setTheme = useThemeStore((s) => s.setTheme);
|
const setTheme = useThemeStore((s) => s.setTheme);
|
||||||
const previewTheme = usePreviewThemeStore((s) => s.previewTheme) ?? "default";
|
const previewTheme = usePreviewThemeStore((s) => s.previewTheme) ?? "default";
|
||||||
const setPreviewTheme = usePreviewThemeStore((s) => s.setPreviewTheme);
|
const setPreviewTheme = usePreviewThemeStore((s) => s.setPreviewTheme);
|
||||||
|
const activeThemeRef = useRef(activeTheme);
|
||||||
|
activeThemeRef.current = activeTheme;
|
||||||
|
|
||||||
const appLanguage = useLanguageStore((s) => s.language);
|
const appLanguage = useLanguageStore((s) => s.language);
|
||||||
const setAppLanguage = useLanguageStore((s) => s.setLanguage);
|
const setAppLanguage = useLanguageStore((s) => s.setLanguage);
|
||||||
@ -145,6 +147,15 @@ export function SettingsPage() {
|
|||||||
enableThumbnails,
|
enableThumbnails,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
() => () => {
|
||||||
|
setPreviewTheme(
|
||||||
|
activeThemeRef.current === "default" ? null : activeThemeRef.current,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[setPreviewTheme],
|
||||||
|
);
|
||||||
|
|
||||||
const setThemeWithPreview = useCallback(
|
const setThemeWithPreview = useCallback(
|
||||||
(v: string | null) => {
|
(v: string | null) => {
|
||||||
state.theme.set(v === "default" ? null : v);
|
state.theme.set(v === "default" ? null : v);
|
||||||
|
Loading…
Reference in New Issue
Block a user