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 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(
|
||||||
|
@ -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;
|
|
||||||
|
@ -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;
|
|
||||||
|
@ -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;
|
modeCookie !== ''
|
||||||
freezeViewports: boolean;
|
? modeCookie
|
||||||
network: 'mainnet' | 'testnet' | undefined;
|
: window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||||
coordinator: Coordinator | undefined;
|
? 'dark'
|
||||||
unsafeClient: boolean;
|
: 'light';
|
||||||
hostedClient: boolean;
|
|
||||||
|
const languageCookie = systemClient.getCookie('settings_language');
|
||||||
|
this.language =
|
||||||
|
languageCookie !== ''
|
||||||
|
? languageCookie
|
||||||
|
: i18n.resolvedLanguage == null
|
||||||
|
? 'en'
|
||||||
|
: i18n.resolvedLanguage.substring(0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
const modeCookie: 'light' | 'dark' | '' = systemClient.getCookie('settings_mode');
|
export default BaseSettings;
|
||||||
const mode: 'light' | 'dark' =
|
|
||||||
modeCookie !== ''
|
|
||||||
? modeCookie
|
|
||||||
: window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
||||||
? 'dark'
|
|
||||||
: 'light';
|
|
||||||
|
|
||||||
const languageCookie = systemClient.getCookie('settings_language');
|
|
||||||
const language: 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,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Settings;
|
|
||||||
|
@ -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';
|
||||||
|
Loading…
Reference in New Issue
Block a user