mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-20 14:37:43 +01:00
Fix theme preview
This commit is contained in:
parent
261ef5e6c5
commit
7c4c02dd83
2 changed files with 25 additions and 18 deletions
|
@ -102,9 +102,9 @@ export function AccountSettings(props: {
|
||||||
|
|
||||||
export function SettingsPage() {
|
export function SettingsPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const activeTheme = useThemeStore((s) => s.theme) ?? "default";
|
const activeTheme = useThemeStore((s) => s.theme);
|
||||||
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);
|
||||||
const setPreviewTheme = usePreviewThemeStore((s) => s.setPreviewTheme);
|
const setPreviewTheme = usePreviewThemeStore((s) => s.setPreviewTheme);
|
||||||
|
|
||||||
const appLanguage = useLanguageStore((s) => s.language);
|
const appLanguage = useLanguageStore((s) => s.language);
|
||||||
|
@ -146,18 +146,21 @@ export function SettingsPage() {
|
||||||
enableThumbnails,
|
enableThumbnails,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Reset the preview theme when the settings page is unmounted
|
useEffect(() => {
|
||||||
useEffect(
|
setPreviewTheme(activeTheme ?? "default");
|
||||||
() => () => {
|
}, [setPreviewTheme, activeTheme]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Clear preview theme on unmount
|
||||||
|
return () => {
|
||||||
setPreviewTheme(null);
|
setPreviewTheme(null);
|
||||||
},
|
};
|
||||||
[setPreviewTheme],
|
}, [setPreviewTheme]);
|
||||||
);
|
|
||||||
|
|
||||||
const setThemeWithPreview = useCallback(
|
const setThemeWithPreview = useCallback(
|
||||||
(v: string | null) => {
|
(theme: string) => {
|
||||||
state.theme.set(v === "default" ? null : v);
|
state.theme.set(theme === "default" ? null : theme);
|
||||||
setPreviewTheme(v);
|
setPreviewTheme(theme);
|
||||||
},
|
},
|
||||||
[state.theme, setPreviewTheme],
|
[state.theme, setPreviewTheme],
|
||||||
);
|
);
|
||||||
|
@ -261,8 +264,8 @@ export function SettingsPage() {
|
||||||
</div>
|
</div>
|
||||||
<div id="settings-appearance" className="mt-48">
|
<div id="settings-appearance" className="mt-48">
|
||||||
<ThemePart
|
<ThemePart
|
||||||
active={previewTheme}
|
active={previewTheme ?? "default"}
|
||||||
inUse={activeTheme}
|
inUse={activeTheme ?? "default"}
|
||||||
setTheme={setThemeWithPreview}
|
setTheme={setThemeWithPreview}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -7,22 +7,27 @@ import { Heading1 } from "@/components/utils/Text";
|
||||||
const availableThemes = [
|
const availableThemes = [
|
||||||
{
|
{
|
||||||
id: "default",
|
id: "default",
|
||||||
|
selector: "theme-default",
|
||||||
key: "settings.appearance.themes.default",
|
key: "settings.appearance.themes.default",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "blue",
|
id: "blue",
|
||||||
|
selector: "theme-blue",
|
||||||
key: "settings.appearance.themes.blue",
|
key: "settings.appearance.themes.blue",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "teal",
|
id: "teal",
|
||||||
|
selector: "theme-teal",
|
||||||
key: "settings.appearance.themes.teal",
|
key: "settings.appearance.themes.teal",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "red",
|
id: "red",
|
||||||
|
selector: "theme-red",
|
||||||
key: "settings.appearance.themes.red",
|
key: "settings.appearance.themes.red",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "gray",
|
id: "gray",
|
||||||
|
selector: "theme-gray",
|
||||||
key: "settings.appearance.themes.gray",
|
key: "settings.appearance.themes.gray",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -121,9 +126,9 @@ function ThemePreview(props: {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ThemePart(props: {
|
export function ThemePart(props: {
|
||||||
active: string | null;
|
active: string;
|
||||||
inUse: string | null;
|
inUse: string;
|
||||||
setTheme: (theme: string | null) => void;
|
setTheme: (theme: string) => void;
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
@ -131,10 +136,9 @@ export function ThemePart(props: {
|
||||||
<div>
|
<div>
|
||||||
<Heading1 border>{t("settings.appearance.title")}</Heading1>
|
<Heading1 border>{t("settings.appearance.title")}</Heading1>
|
||||||
<div className="grid grid-cols-[repeat(auto-fill,minmax(160px,1fr))] gap-6 max-w-[700px]">
|
<div className="grid grid-cols-[repeat(auto-fill,minmax(160px,1fr))] gap-6 max-w-[700px]">
|
||||||
{/* default theme */}
|
|
||||||
{availableThemes.map((v) => (
|
{availableThemes.map((v) => (
|
||||||
<ThemePreview
|
<ThemePreview
|
||||||
selector={`theme-${v.id}`}
|
selector={v.selector}
|
||||||
active={props.active === v.id}
|
active={props.active === v.id}
|
||||||
inUse={props.inUse === v.id}
|
inUse={props.inUse === v.id}
|
||||||
name={t(v.key)}
|
name={t(v.key)}
|
||||||
|
|
Loading…
Reference in a new issue