Update layout store to use enum

This commit is contained in:
Matthias 2020-10-06 07:59:05 +02:00
parent 1a046041d7
commit a714b11782
4 changed files with 48 additions and 16 deletions

View File

@ -48,6 +48,7 @@ import LoginModal from '@/views/LoginModal.vue';
import { State, Action, namespace } from 'vuex-class'; import { State, Action, namespace } from 'vuex-class';
import userService from '@/shared/userService'; import userService from '@/shared/userService';
import BootswatchThemeSelect from '@/components/BootswatchThemeSelect.vue'; import BootswatchThemeSelect from '@/components/BootswatchThemeSelect.vue';
import { LayoutActions } from '@/store/modules/layout';
const ftbot = namespace('ftbot'); const ftbot = namespace('ftbot');
const layoutNs = namespace('layout'); const layoutNs = namespace('layout');
@ -66,9 +67,9 @@ export default class NavBar extends Vue {
@ftbot.Action ping; @ftbot.Action ping;
@layoutNs.Action resetDashboardLayout; @layoutNs.Action [LayoutActions.resetDashboardLayout];
@layoutNs.Action resetTradingLayout; @layoutNs.Action [LayoutActions.resetTradingLayout];
mounted() { mounted() {
this.ping(); this.ping();

View File

@ -17,6 +17,23 @@ export enum DashboardLayout {
cumChartChart = 'g-cumChartChart', cumChartChart = 'g-cumChartChart',
} }
export enum LayoutGetters {
getDashboardLayout = 'getDashboardLayout',
getTradingLayout = 'getTradingLayout',
}
export enum LayoutActions {
setDashboardLayout = 'setDashboardLayout',
setTradingLayout = 'setTradingLayout',
resetDashboardLayout = 'resetDashboardLayout',
resetTradingLayout = 'resetTradingLayout',
}
enum LayoutMutations {
setDashboardLayout = 'setDashboardLayout',
setTradingLayout = 'setTradingLayout',
}
// Define default layouts // Define default layouts
const DEFAULT_TRADING_LAYOUT: GridItemData[] = [ const DEFAULT_TRADING_LAYOUT: GridItemData[] = [
{ i: TradeLayout.botControls, x: 0, y: 0, w: 4, h: 4 }, { i: TradeLayout.botControls, x: 0, y: 0, w: 4, h: 4 },
@ -68,33 +85,42 @@ export default {
}, },
getters: { getters: {
getDashboardLayout(state) { [LayoutGetters.getDashboardLayout](state) {
return state.dashboardLayout; return state.dashboardLayout;
}, },
getTradingLayout(state) { [LayoutGetters.getTradingLayout](state) {
return state.tradingLayout; return state.tradingLayout;
}, },
}, },
mutations: { mutations: {
setDashboardLayout(state, layout) { [LayoutMutations.setDashboardLayout](state, layout) {
console.log('set dashboard layout'); console.log('set dashboard layout');
state.dashboardLayout = layout; state.dashboardLayout = layout;
localStorage.setItem(STORE_DASHBOARD_LAYOUT, JSON.stringify(layout)); localStorage.setItem(STORE_DASHBOARD_LAYOUT, JSON.stringify(layout));
}, },
setTradingLayout(state, layout) { [LayoutMutations.setTradingLayout](state, layout) {
state.tradingLayout = layout; state.tradingLayout = layout;
localStorage.setItem(STORE_TRADING_LAYOUT, JSON.stringify(layout)); localStorage.setItem(STORE_TRADING_LAYOUT, JSON.stringify(layout));
}, },
}, },
actions: { actions: {
resetDashboardLayout({ commit }) { [LayoutActions.setDashboardLayout]({ commit }, layout) {
commit('setDashboardLayout', JSON.parse(JSON.stringify(DEFAULT_DASHBOARD_LAYOUT))); commit(LayoutMutations.setDashboardLayout, layout);
},
[LayoutActions.setTradingLayout]({ commit }, layout) {
commit(LayoutMutations.setTradingLayout, layout);
},
[LayoutActions.resetDashboardLayout]({ commit }) {
commit(
LayoutMutations.setDashboardLayout,
JSON.parse(JSON.stringify(DEFAULT_DASHBOARD_LAYOUT)),
);
}, },
resetTradingLayout({ commit }) { [LayoutActions.resetTradingLayout]({ commit }) {
commit('setTradingLayout', JSON.parse(JSON.stringify(DEFAULT_TRADING_LAYOUT))); commit(LayoutMutations.setTradingLayout, JSON.parse(JSON.stringify(DEFAULT_TRADING_LAYOUT)));
}, },
}, },
}; };

View File

@ -109,7 +109,12 @@ import HourlyChart from '@/components/charts/HourlyChart.vue';
import CumProfitChart from '@/components/charts/CumProfitChart.vue'; import CumProfitChart from '@/components/charts/CumProfitChart.vue';
import DraggableContainer from '@/components/layout/DraggableContainer.vue'; import DraggableContainer from '@/components/layout/DraggableContainer.vue';
import { DashboardLayout, findGridLayout } from '@/store/modules/layout'; import {
DashboardLayout,
findGridLayout,
LayoutActions,
LayoutGetters,
} from '@/store/modules/layout';
import { Trade, DailyReturnValue, BalanceInterface, ProfitInterface, DailyPayload } from '@/types'; import { Trade, DailyReturnValue, BalanceInterface, ProfitInterface, DailyPayload } from '@/types';
const ftbot = namespace('ftbot'); const ftbot = namespace('ftbot');
@ -145,9 +150,9 @@ export default class Dashboard extends Vue {
@ftbot.Action getTrades; @ftbot.Action getTrades;
@layoutNs.Getter getDashboardLayout!: GridItemData[]; @layoutNs.Getter [LayoutGetters.getDashboardLayout]!: GridItemData[];
@layoutNs.Mutation setDashboardLayout; @layoutNs.Action [LayoutActions.setDashboardLayout];
@ftbot.Action getOpenTrades; @ftbot.Action getOpenTrades;

View File

@ -151,7 +151,7 @@ import CandleChartContainer from '@/components/charts/CandleChartContainer.vue';
import { Trade } from '@/types'; import { Trade } from '@/types';
import { BotStoreGetters } from '@/store/modules/ftbot'; import { BotStoreGetters } from '@/store/modules/ftbot';
import { TradeLayout, findGridLayout } from '@/store/modules/layout'; import { TradeLayout, findGridLayout, LayoutGetters, LayoutActions } from '@/store/modules/layout';
const ftbot = namespace('ftbot'); const ftbot = namespace('ftbot');
const layoutNs = namespace('layout'); const layoutNs = namespace('layout');
@ -189,9 +189,9 @@ export default class Trading extends Vue {
@ftbot.State whitelist!: string[]; @ftbot.State whitelist!: string[];
@layoutNs.Getter getTradingLayout!: GridItemData[]; @layoutNs.Getter [LayoutGetters.getTradingLayout]!: GridItemData[];
@layoutNs.Mutation setTradingLayout; @layoutNs.Action [LayoutActions.setTradingLayout];
get gridLayout(): GridItemData[] { get gridLayout(): GridItemData[] {
return this.getTradingLayout; return this.getTradingLayout;