mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-10 16:21:36 +00:00
Fix load setting cookies
This commit is contained in:
parent
268855743e
commit
cf1fd8b28c
@ -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(
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { systemClient } from '../services/System';
|
||||
import { baseSettings, Settings } from './Settings.model';
|
||||
import BaseSettings from './Settings.model';
|
||||
|
||||
const fontSizeCookie = systemClient.getCookie('settings_fontsize_basic');
|
||||
const fontSize = fontSizeCookie !== '' ? Number(fontSizeCookie) : 14;
|
||||
class Settings extends BaseSettings {
|
||||
constructor() {
|
||||
super();
|
||||
const fontSizeCookie = systemClient.getCookie('settings_fontsize_basic');
|
||||
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;
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { systemClient } from '../services/System';
|
||||
import { baseSettings, Settings } from './Settings.model';
|
||||
import BaseSettings from './Settings.model';
|
||||
|
||||
const fontSizeCookie = systemClient.getCookie('settings_fontsize_pro');
|
||||
const fontSize = fontSizeCookie !== '' ? Number(fontSizeCookie) : 12;
|
||||
class Settings extends BaseSettings {
|
||||
constructor() {
|
||||
super();
|
||||
const fontSizeCookie = systemClient.getCookie('settings_fontsize_pro');
|
||||
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;
|
||||
|
@ -20,44 +20,34 @@ 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;
|
||||
}
|
||||
|
||||
const modeCookie: 'light' | 'dark' | '' = systemClient.getCookie('settings_mode');
|
||||
const mode: 'light' | 'dark' =
|
||||
class BaseSettings {
|
||||
constructor() {
|
||||
const modeCookie: 'light' | 'dark' | '' = systemClient.getCookie('settings_mode');
|
||||
this.mode =
|
||||
modeCookie !== ''
|
||||
? modeCookie
|
||||
: window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
? 'dark'
|
||||
: 'light';
|
||||
|
||||
const languageCookie = systemClient.getCookie('settings_language');
|
||||
const language: Language =
|
||||
const languageCookie = systemClient.getCookie('settings_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;
|
||||
|
@ -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';
|
||||
|
Loading…
Reference in New Issue
Block a user