frequi_origin/src/stores/settings.ts

63 lines
1.4 KiB
TypeScript
Raw Normal View History

import { defineStore } from 'pinia';
import { setTimezone } from '@/shared/formatters';
import { getCurrentTheme, getTheme } from '@/shared/themes';
2022-04-19 18:20:46 +00:00
import axios from 'axios';
import { UiVersion } from '@/types';
const STORE_UI_SETTINGS = 'ftUISettings';
export enum OpenTradeVizOptions {
showPill = 'showPill',
asTitle = 'asTitle',
noOpenTrades = 'noOpenTrades',
}
export interface SettingsType {
openTradesInTitle?: string;
timezone?: string;
backgroundSync?: boolean;
}
export const useSettingsStore = defineStore('uiSettings', {
// other options...
state: () => {
return {
openTradesInTitle: OpenTradeVizOptions.showPill as string,
timezone: 'UTC',
backgroundSync: true,
currentTheme: getCurrentTheme(),
2022-04-19 18:20:46 +00:00
uiVersion: 'dev',
2022-07-11 14:33:47 +00:00
useHeikinAshiCandles: false,
};
},
getters: {
isDarkTheme(state) {
const theme = getTheme(state.currentTheme);
if (theme) {
return theme.dark;
}
return true;
},
chartTheme(): string {
return this.isDarkTheme ? 'dark' : 'light';
},
},
actions: {
2022-04-19 18:20:46 +00:00
async loadUIVersion() {
if (import.meta.env.PROD) {
try {
const result = await axios.get<UiVersion>('/ui_version');
const { version } = result.data;
this.uiVersion = version;
} catch (error) {
//
}
}
},
},
persist: {
key: STORE_UI_SETTINGS,
},
});