From 246417ebc289593cfbbc0fb4a9437510e2d55e40 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 19 Aug 2020 19:28:23 +0200 Subject: [PATCH] Store layouts in localStorage --- src/store/modules/layout.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/store/modules/layout.ts b/src/store/modules/layout.ts index f1ee533d..91b41401 100644 --- a/src/store/modules/layout.ts +++ b/src/store/modules/layout.ts @@ -15,11 +15,23 @@ const DEFAULT_DASHBOARD_LAYOUT: GridItemData[] = [ { i: 'g-cumChartChart', x: 0, y: 6, w: 4, h: 6 }, ]; +const STORE_DASHBOARD_LAYOUT = 'ftDashboardLayout'; +const STORE_TRADING_LAYOUT = 'ftTradingLayout'; + +function getLayout(storageString: string, defaultLayout: GridItemData[]) { + const fromStore = localStorage.getItem(storageString); + if (fromStore) { + return JSON.parse(fromStore); + } + + return JSON.parse(JSON.stringify(defaultLayout)); +} + export default { namespaced: true, state: { - dashboardLayout: JSON.parse(JSON.stringify(DEFAULT_DASHBOARD_LAYOUT)), - tradingLayout: JSON.parse(JSON.stringify(DEFAULT_TRADING_LAYOUT)), + dashboardLayout: getLayout(STORE_DASHBOARD_LAYOUT, DEFAULT_DASHBOARD_LAYOUT), + tradingLayout: getLayout(STORE_TRADING_LAYOUT, DEFAULT_TRADING_LAYOUT), }, getters: { @@ -35,9 +47,11 @@ export default { setDashboardLayout(state, layout) { console.log('set dashboard layout'); state.dashboardLayout = layout; + localStorage.setItem(STORE_DASHBOARD_LAYOUT, JSON.stringify(layout)); }, setTradingLayout(state, layout) { state.tradingLayout = layout; + localStorage.setItem(STORE_TRADING_LAYOUT, JSON.stringify(layout)); }, },