mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-29 16:07:40 +01:00
Fix theme not applying on body colors
This commit is contained in:
parent
615e44b231
commit
9fce50d259
4 changed files with 47 additions and 35 deletions
|
@ -28,7 +28,7 @@ import { BookmarkSyncer } from "@/stores/bookmarks/BookmarkSyncer";
|
||||||
import { useLanguageStore } from "@/stores/language";
|
import { useLanguageStore } from "@/stores/language";
|
||||||
import { ProgressSyncer } from "@/stores/progress/ProgressSyncer";
|
import { ProgressSyncer } from "@/stores/progress/ProgressSyncer";
|
||||||
import { SettingsSyncer } from "@/stores/subtitles/SettingsSyncer";
|
import { SettingsSyncer } from "@/stores/subtitles/SettingsSyncer";
|
||||||
import { useThemeStore } from "@/stores/theme";
|
import { ThemeProvider } from "@/stores/theme";
|
||||||
|
|
||||||
import { initializeChromecast } from "./setup/chromecast";
|
import { initializeChromecast } from "./setup/chromecast";
|
||||||
import { initializeOldStores } from "./stores/__old/migrations";
|
import { initializeOldStores } from "./stores/__old/migrations";
|
||||||
|
@ -124,19 +124,12 @@ function TheRouter(props: { children: ReactNode }) {
|
||||||
return <HashRouter>{props.children}</HashRouter>;
|
return <HashRouter>{props.children}</HashRouter>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ThemeProvider(props: { children: ReactNode }) {
|
|
||||||
const theme = useThemeStore((s) => s.theme);
|
|
||||||
const themeSelector = theme ? `theme-${theme}` : undefined;
|
|
||||||
|
|
||||||
return <div className={themeSelector}>{props.children}</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<HelmetProvider>
|
<HelmetProvider>
|
||||||
<Suspense fallback={<LoadingScreen type="lazy" />}>
|
<Suspense fallback={<LoadingScreen type="lazy" />}>
|
||||||
<ThemeProvider>
|
<ThemeProvider applyGlobal>
|
||||||
<ProgressSyncer />
|
<ProgressSyncer />
|
||||||
<BookmarkSyncer />
|
<BookmarkSyncer />
|
||||||
<SettingsSyncer />
|
<SettingsSyncer />
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
import { create } from "zustand";
|
|
||||||
import { persist } from "zustand/middleware";
|
|
||||||
import { immer } from "zustand/middleware/immer";
|
|
||||||
|
|
||||||
export interface ThemeStore {
|
|
||||||
theme: string | null;
|
|
||||||
setTheme(v: string | null): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useThemeStore = create(
|
|
||||||
persist(
|
|
||||||
immer<ThemeStore>((set) => ({
|
|
||||||
theme: null,
|
|
||||||
setTheme(v) {
|
|
||||||
set((s) => {
|
|
||||||
s.theme = v;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
})),
|
|
||||||
{
|
|
||||||
name: "__MW::theme",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
45
src/stores/theme/index.tsx
Normal file
45
src/stores/theme/index.tsx
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
import { ReactNode } from "react";
|
||||||
|
import { Helmet } from "react-helmet-async";
|
||||||
|
import { create } from "zustand";
|
||||||
|
import { persist } from "zustand/middleware";
|
||||||
|
import { immer } from "zustand/middleware/immer";
|
||||||
|
|
||||||
|
export interface ThemeStore {
|
||||||
|
theme: string | null;
|
||||||
|
setTheme(v: string | null): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useThemeStore = create(
|
||||||
|
persist(
|
||||||
|
immer<ThemeStore>((set) => ({
|
||||||
|
theme: null,
|
||||||
|
setTheme(v) {
|
||||||
|
set((s) => {
|
||||||
|
s.theme = v;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
{
|
||||||
|
name: "__MW::theme",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
export function ThemeProvider(props: {
|
||||||
|
children?: ReactNode;
|
||||||
|
applyGlobal?: boolean;
|
||||||
|
}) {
|
||||||
|
const theme = useThemeStore((s) => s.theme);
|
||||||
|
const themeSelector = theme ? `theme-${theme}` : undefined;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={themeSelector}>
|
||||||
|
{props.applyGlobal ? (
|
||||||
|
<Helmet>
|
||||||
|
<body className={themeSelector} />
|
||||||
|
</Helmet>
|
||||||
|
) : null}
|
||||||
|
{props.children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -83,8 +83,6 @@ const tokens = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO body background isn't themed
|
|
||||||
|
|
||||||
export const defaultTheme = {
|
export const defaultTheme = {
|
||||||
extend: {
|
extend: {
|
||||||
colors: {
|
colors: {
|
||||||
|
|
Loading…
Reference in a new issue