Skip to content

Commit 402f4c6

Browse files
committed
🐛 fix: 默认注入主题
1 parent 67bc581 commit 402f4c6

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/layout/AppTheme.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
'use client';
22

33
import { NeutralColors, PrimaryColors, ThemeProvider } from '@lobehub/ui';
4-
import { createStyles } from 'antd-style';
4+
import { ThemeAppearance, createStyles } from 'antd-style';
55
import { ReactNode, memo, useEffect } from 'react';
66

7-
import { VIDOL_THEME_NEUTRAL_COLOR, VIDOL_THEME_PRIMARY_COLOR } from '@/constants/theme';
7+
import {
8+
VIDOL_THEME_APPEARANCE,
9+
VIDOL_THEME_NEUTRAL_COLOR,
10+
VIDOL_THEME_PRIMARY_COLOR,
11+
} from '@/constants/theme';
812
import { useGlobalStore } from '@/store/global';
913
import { useSettingStore } from '@/store/setting';
1014
import { GlobalStyle } from '@/styles';
1115
import { setCookie } from '@/utils/cookie';
1216

1317
export interface AppThemeProps {
1418
children?: ReactNode;
19+
defaultAppearance?: ThemeAppearance;
1520
defaultNeutralColor?: NeutralColors;
1621
defaultPrimaryColor?: PrimaryColors;
1722
}
@@ -28,7 +33,7 @@ const useStyles = createStyles(({ css }) => ({
2833
}));
2934

3035
const AppTheme = memo((props: AppThemeProps) => {
31-
const { children, defaultNeutralColor, defaultPrimaryColor } = props;
36+
const { children, defaultNeutralColor, defaultAppearance, defaultPrimaryColor } = props;
3237
const [primaryColor, neutralColor] = useSettingStore((s) => [
3338
s.config.primaryColor,
3439
s.config.neutralColor,
@@ -52,6 +57,10 @@ const AppTheme = memo((props: AppThemeProps) => {
5257
primaryColor: primaryColor ?? defaultPrimaryColor,
5358
neutralColor: neutralColor ?? defaultNeutralColor,
5459
}}
60+
defaultAppearance={defaultAppearance}
61+
onAppearanceChange={(appearance) => {
62+
setCookie(VIDOL_THEME_APPEARANCE, appearance);
63+
}}
5564
themeMode={themeMode}
5665
>
5766
<GlobalStyle />

src/layout/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { ReactNode } from 'react';
55
import { resolveAcceptLanguage } from 'resolve-accept-language';
66

77
import { LOBE_LOCALE_COOKIE } from '@/constants/locale';
8-
import { VIDOL_THEME_NEUTRAL_COLOR, VIDOL_THEME_PRIMARY_COLOR } from '@/constants/theme';
8+
import {
9+
VIDOL_THEME_APPEARANCE,
10+
VIDOL_THEME_NEUTRAL_COLOR,
11+
VIDOL_THEME_PRIMARY_COLOR,
12+
} from '@/constants/theme';
913
import AppTheme from '@/layout/AppTheme';
1014
import StoreHydration from '@/layout/StoreHydration';
1115
import StyleRegistry from '@/layout/StyleRegistry';
@@ -40,6 +44,8 @@ const Layout = async (props: LayoutProps) => {
4044
const { children } = props;
4145

4246
const cookieStore = cookies();
47+
const appearance = cookieStore.get(VIDOL_THEME_APPEARANCE);
48+
4349
const primaryColor = cookieStore.get(VIDOL_THEME_PRIMARY_COLOR);
4450
const neutralColor = cookieStore.get(VIDOL_THEME_NEUTRAL_COLOR);
4551

@@ -54,6 +60,7 @@ const Layout = async (props: LayoutProps) => {
5460
<StyleRegistry>
5561
<Locale antdLocale={antdLocale} defaultLang={userLocale}>
5662
<AppTheme
63+
defaultAppearance={appearance?.value}
5764
defaultNeutralColor={neutralColor?.value as any}
5865
defaultPrimaryColor={primaryColor?.value as any}
5966
>

0 commit comments

Comments
 (0)