RWKV-Runner/frontend/src/pages/Settings.tsx

94 lines
3.1 KiB
TypeScript
Raw Normal View History

2023-05-21 16:04:18 +00:00
import React, { FC } from 'react';
import { Page } from '../components/Page';
import { Dropdown, Option, Switch } from '@fluentui/react-components';
import { Labeled } from '../components/Labeled';
2023-05-17 15:27:52 +00:00
import commonStore from '../stores/commonStore';
2023-05-21 16:04:18 +00:00
import { observer } from 'mobx-react-lite';
import { useTranslation } from 'react-i18next';
import { checkUpdate } from '../utils';
2023-05-20 08:07:08 +00:00
export const Languages = {
dev: 'English', // i18n default
zh: '简体中文'
};
export type Language = keyof typeof Languages;
2023-05-20 08:33:32 +00:00
export type SettingsType = {
2023-05-20 08:07:08 +00:00
language: Language,
darkMode: boolean
autoUpdatesCheck: boolean
2023-05-21 16:04:18 +00:00
giteeUpdatesSource: boolean
2023-05-21 02:49:45 +00:00
cnMirror: boolean
2023-05-20 08:07:08 +00:00
}
2023-05-05 15:23:34 +00:00
2023-05-17 15:27:52 +00:00
export const Settings: FC = observer(() => {
2023-05-21 16:04:18 +00:00
const { t, i18n } = useTranslation();
2023-05-18 11:25:13 +00:00
2023-05-05 15:23:34 +00:00
return (
2023-05-18 11:25:13 +00:00
<Page title={t('Settings')} content={
2023-05-17 15:27:52 +00:00
<div className="flex flex-col gap-2 overflow-hidden">
2023-05-18 12:48:53 +00:00
<Labeled label={t('Language')} flex spaceBetween content={
2023-05-21 16:04:18 +00:00
<Dropdown style={{ minWidth: 0 }} listbox={{ style: { minWidth: 0 } }}
value={Languages[commonStore.settings.language]}
selectedOptions={[commonStore.settings.language]}
onOptionSelect={(_, data) => {
if (data.optionValue) {
const lang = data.optionValue as Language;
commonStore.setSettings({
language: lang
});
i18n.changeLanguage(lang);
}
}}>
2023-05-18 11:25:13 +00:00
{
Object.entries(Languages).map(([langKey, desc]) =>
<Option key={langKey} value={langKey}>{desc}</Option>)
}
2023-05-17 15:27:52 +00:00
</Dropdown>
2023-05-21 16:04:18 +00:00
} />
2023-05-18 12:48:53 +00:00
<Labeled label={t('Dark Mode')} flex spaceBetween content={
2023-05-17 15:27:52 +00:00
<Switch checked={commonStore.settings.darkMode}
2023-05-21 16:04:18 +00:00
onChange={(e, data) => {
commonStore.setSettings({
darkMode: data.checked
});
}} />
} />
2023-05-18 12:48:53 +00:00
<Labeled label={t('Automatic Updates Check')} flex spaceBetween content={
2023-05-17 15:27:52 +00:00
<Switch checked={commonStore.settings.autoUpdatesCheck}
2023-05-21 16:04:18 +00:00
onChange={(e, data) => {
commonStore.setSettings({
autoUpdatesCheck: data.checked
});
if (data.checked)
checkUpdate(true);
}} />
} />
{
commonStore.settings.language === 'zh' &&
<Labeled label={t('Use Gitee Updates Source')} flex spaceBetween content={
<Switch checked={commonStore.settings.giteeUpdatesSource}
onChange={(e, data) => {
commonStore.setSettings({
giteeUpdatesSource: data.checked
});
}} />
} />
}
2023-05-21 02:49:45 +00:00
{
commonStore.settings.language === 'zh' &&
<Labeled label={t('Use Tsinghua Pip Mirrors')} flex spaceBetween content={
<Switch checked={commonStore.settings.cnMirror}
2023-05-21 16:04:18 +00:00
onChange={(e, data) => {
commonStore.setSettings({
cnMirror: data.checked
});
}} />
} />
2023-05-21 02:49:45 +00:00
}
2023-05-17 15:27:52 +00:00
</div>
2023-05-21 16:04:18 +00:00
} />
2023-05-05 15:23:34 +00:00
);
2023-05-17 15:27:52 +00:00
});