Fix load setting cookies

This commit is contained in:
Reckless_Satoshi 2022-11-06 09:00:13 -08:00
parent 268855743e
commit cf1fd8b28c
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
5 changed files with 56 additions and 67 deletions

View File

@ -10,21 +10,21 @@ import { I18nextProvider } from 'react-i18next';
import i18n from './i18n/Web'; import i18n from './i18n/Web';
import { systemClient } from './services/System'; import { systemClient } from './services/System';
import { Settings, defaultSettings } from './models'; import { Settings } from './models';
const defaultTheme: Theme = createTheme({ const defaultTheme: Theme = createTheme({
palette: { palette: {
mode: defaultSettings.mode, mode: new Settings().mode,
background: { background: {
default: defaultSettings.mode === 'dark' ? '#070707' : '#fff', default: new Settings().mode === 'dark' ? '#070707' : '#fff',
}, },
}, },
typography: { fontSize: defaultSettings.fontSize }, typography: { fontSize: new Settings().fontSize },
}); });
const App = (): JSX.Element => { const App = (): JSX.Element => {
const [theme, setTheme] = useState<Theme>(defaultTheme); const [theme, setTheme] = useState<Theme>(defaultTheme);
const [settings, setSettings] = useState<Settings>(defaultSettings); const [settings, setSettings] = useState<Settings>(new Settings());
const updateTheme = function () { const updateTheme = function () {
setTheme( setTheme(

View File

@ -1,13 +1,13 @@
import { systemClient } from '../services/System'; import { systemClient } from '../services/System';
import { baseSettings, Settings } from './Settings.model'; import BaseSettings from './Settings.model';
const fontSizeCookie = systemClient.getCookie('settings_fontsize_basic'); class Settings extends BaseSettings {
const fontSize = fontSizeCookie !== '' ? Number(fontSizeCookie) : 14; constructor() {
super();
const fontSizeCookie = systemClient.getCookie('settings_fontsize_basic');
this.fontSize = fontSizeCookie !== '' ? Number(fontSizeCookie) : 14;
}
public frontend: 'basic' | 'pro' = 'basic';
}
export const defaultSettings: Settings = { export default Settings;
...baseSettings,
frontend: 'basic',
fontSize: fontSize,
};
export default defaultSettings;

View File

@ -1,13 +1,13 @@
import { systemClient } from '../services/System'; import { systemClient } from '../services/System';
import { baseSettings, Settings } from './Settings.model'; import BaseSettings from './Settings.model';
const fontSizeCookie = systemClient.getCookie('settings_fontsize_pro'); class Settings extends BaseSettings {
const fontSize = fontSizeCookie !== '' ? Number(fontSizeCookie) : 12; constructor() {
super();
const fontSizeCookie = systemClient.getCookie('settings_fontsize_pro');
this.fontSize = fontSizeCookie !== '' ? Number(fontSizeCookie) : 12;
}
public frontend: 'basic' | 'pro' = 'pro';
}
export const defaultSettings: Settings = { export default Settings;
...baseSettings,
frontend: 'pro',
fontSize: fontSize,
};
export default defaultSettings;

View File

@ -20,44 +20,34 @@ export type Language =
| 'zh-SI' | 'zh-SI'
| 'zh-TR'; | 'zh-TR';
export interface Settings { class BaseSettings {
frontend: 'basic' | 'pro'; constructor() {
mode: 'light' | 'dark'; const modeCookie: 'light' | 'dark' | '' = systemClient.getCookie('settings_mode');
fontSize: number; this.mode =
language: Language;
freezeViewports: boolean;
network: 'mainnet' | 'testnet' | undefined;
coordinator: Coordinator | undefined;
unsafeClient: boolean;
hostedClient: boolean;
}
const modeCookie: 'light' | 'dark' | '' = systemClient.getCookie('settings_mode');
const mode: 'light' | 'dark' =
modeCookie !== '' modeCookie !== ''
? modeCookie ? modeCookie
: window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches : window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark' ? 'dark'
: 'light'; : 'light';
const languageCookie = systemClient.getCookie('settings_language'); const languageCookie = systemClient.getCookie('settings_language');
const language: Language = this.language =
languageCookie !== '' languageCookie !== ''
? languageCookie ? languageCookie
: i18n.resolvedLanguage == null : i18n.resolvedLanguage == null
? 'en' ? 'en'
: i18n.resolvedLanguage.substring(0, 2); : i18n.resolvedLanguage.substring(0, 2);
}
export const baseSettings: Settings = { public frontend: 'basic' | 'pro' = 'basic';
frontend: 'basic', public mode: 'light' | 'dark' = 'light';
mode: mode, public fontSize: number = 14;
fontSize: 14, public language?: Language;
language: language, public freezeViewports: boolean = false;
freezeViewports: false, public network: 'mainnet' | 'testnet' | undefined = 'mainnet';
network: undefined, public coordinator: Coordinator | undefined = undefined;
coordinator: undefined, public unsafeClient: boolean = false;
unsafeClient: false, public hostedClient: boolean = false;
hostedClient: false, }
};
export default Settings; export default BaseSettings;

View File

@ -1,5 +1,6 @@
import Robot from './Robot.model'; import Robot from './Robot.model';
export { Robot }; import Settings from './Settings.default.basic';
export { Robot, Settings };
export type { LimitList } from './Limit.model'; export type { LimitList } from './Limit.model';
export type { Limit } from './Limit.model'; export type { Limit } from './Limit.model';
@ -8,12 +9,10 @@ export type { Order } from './Order.model';
export type { PublicOrder } from './Book.model'; export type { PublicOrder } from './Book.model';
export type { Book } from './Book.model'; export type { Book } from './Book.model';
export type { Info } from './Info.model'; export type { Info } from './Info.model';
export type { Settings } from './Settings.model';
export type { Language } from './Settings.model'; export type { Language } from './Settings.model';
export type { Favorites } from './Favorites.model'; export type { Favorites } from './Favorites.model';
export type { Coordinator } from './Coordinator.model'; export type { Coordinator } from './Coordinator.model';
export type { APIChat, WebSocketsChatMessage, APIChatMessage } from './Chat.model'; export type { APIChat, WebSocketsChatMessage, APIChatMessage } from './Chat.model';
export { defaultMaker } from './Maker.model'; export { defaultMaker } from './Maker.model';
export { defaultSettings } from './Settings.default.basic';
export { defaultInfo } from './Info.model'; export { defaultInfo } from './Info.model';