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 { systemClient } from './services/System';
import { Settings, defaultSettings } from './models';
import { Settings } from './models';
const defaultTheme: Theme = createTheme({
palette: {
mode: defaultSettings.mode,
mode: new Settings().mode,
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 [theme, setTheme] = useState<Theme>(defaultTheme);
const [settings, setSettings] = useState<Settings>(defaultSettings);
const [settings, setSettings] = useState<Settings>(new Settings());
const updateTheme = function () {
setTheme(

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
import Robot from './Robot.model';
export { Robot };
import Settings from './Settings.default.basic';
export { Robot, Settings };
export type { LimitList } 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 { Book } from './Book.model';
export type { Info } from './Info.model';
export type { Settings } from './Settings.model';
export type { Language } from './Settings.model';
export type { Favorites } from './Favorites.model';
export type { Coordinator } from './Coordinator.model';
export type { APIChat, WebSocketsChatMessage, APIChatMessage } from './Chat.model';
export { defaultMaker } from './Maker.model';
export { defaultSettings } from './Settings.default.basic';
export { defaultInfo } from './Info.model';