🐛 fix: fix setting render [force patch]

pull/240/head
canisminor1990 2023-07-05 13:13:38 +08:00
parent 276cda17d0
commit f147b11c07
6 changed files with 268 additions and 253 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,8 @@
import { type SelectProps } from 'antd';
export const i18nOptions: SelectProps['options'] = [
export type I18n = 'en_US' | 'zh-CN' | 'zh_HK' | 'ja_JP' | 'ko_KR';
export const I18nOptions: SelectProps['options'] = [
{
label: 'English',
value: 'en_US',

View File

@ -23,31 +23,31 @@ const Footer = memo<DivProps>(({ className, ...props }) => {
}, []);
return (
<div className={cx(styles.footer, className)} {...props}>
{setting.layoutHideFooter ? (
<div ref={footerReference} />
) : (
<F
bottom={<div ref={footerReference} />}
columns={[
{
items: Resources,
title: t('resources'),
},
{
items: Community,
title: t('community'),
},
{
items: Help,
title: t('help'),
},
{
items: MoreProducts,
title: t('moreProducts'),
},
]}
/>
)}
<F
bottom={<div ref={footerReference} />}
columns={
setting.layoutHideFooter ?
[] :
[
{
items: Resources,
title: t('resources'),
},
{
items: Community,
title: t('community'),
},
{
items: Help,
title: t('help'),
},
{
items: MoreProducts,
title: t('moreProducts'),
},
]
}
/>
</div>
);
});

View File

@ -14,7 +14,7 @@ import { useTranslation } from 'react-i18next';
import { shallow } from 'zustand/shallow';
import { CustomLogo } from '@/components';
import { i18nOptions } from '@/i18n';
import { I18nOptions } from '@/i18n';
import { NeutralColor, PrimaryColor, WebuiSetting, defaultSetting, useAppStore } from '@/store';
import { colors, findKey, neutralColors, primaryColors } from './data';
@ -56,20 +56,24 @@ const SettingForm = memo(() => {
const settingSubmitButton = gradioApp().querySelector('#settings_submit') as HTMLButtonElement;
if (settingDom && settingSubmitButton) {
settingDom.focus();
settingDom.value = JSON.stringify(rawSetting);
settingDom.value = JSON.stringify({
...rawSetting,
neutralColor,
primaryColor,
});
settingDom.blur();
setTimeout(() => {
settingSubmitButton.click();
}, 1000);
}
}, [rawSetting]);
}, [rawSetting, primaryColor, neutralColor]);
const items: FormProps['items'] = useMemo(
() => [
{
children: [
{
children: <Select options={i18nOptions} />,
children: <Select options={I18nOptions} />,
desc: t('settingLanguageDesc'),
label: t('settingLanguage'),
name: 'i18n',
@ -330,6 +334,8 @@ const SettingForm = memo(() => {
rawSetting.enableSidebar,
rawSetting.logoCustomTitle,
rawSetting.logoCustomTitle,
primaryColor,
neutralColor,
],
);

View File

@ -1,9 +1,10 @@
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';
export const SETTING_KEY = 'SD-KITCHEN-SETTING';
import { I18n } from '@/i18n';
export type I18n = 'en_US' | 'zh-CN';
export const SETTING_KEY = 'SD-LOBE-SETTING';
export const FALLBACK_SETTING_KEY = 'SD-KITCHEN-SETTING';
export type PrimaryColor =
| 'blue'
@ -94,10 +95,15 @@ export const useAppStore = create<AppState>()(
onLoadSetting: () => {
console.time('🤯 [setting] loaded');
let localSetting: any = localStorage.getItem(SETTING_KEY);
let webuiSetting: any = (window as any)?.opts?.['opts.lobe_theme_config'];
const fallbackLocalSetting: any = localStorage.getItem(FALLBACK_SETTING_KEY);
const webuiSetting: any = (window as any)?.opts?.['opts.lobe_theme_config'];
if (localSetting) {
console.info('🤯 [setting] loaded local setting');
localSetting = JSON.parse(localSetting);
} else if (fallbackLocalSetting) {
console.info('🤯 [setting] loaded fallback local setting');
localSetting = JSON.parse(fallbackLocalSetting);
} else if (webuiSetting) {
console.info('🤯 [setting] loaded webui setting');
localSetting = JSON.parse(webuiSetting);