Remove vuex
This commit is contained in:
@ -3,7 +3,10 @@ import App from './App.vue'
|
||||
import './index.css'
|
||||
import router from './router'
|
||||
import { createPinia } from 'pinia'
|
||||
import { SET_CURRENT_ACCOUNT, SET_CURRENT_BUDGET } from './store/action-types'
|
||||
import { useBudgetsStore } from './stores/budget';
|
||||
import { useSessionStore } from './stores/session';
|
||||
import { useSettingsStore } from './stores/settings';
|
||||
import { useAccountStore } from './stores/budget-account'
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(router)
|
||||
@ -11,10 +14,30 @@ app.use(createPinia())
|
||||
app.mount('#app')
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
await store.dispatch(SET_CURRENT_BUDGET, to.params.budgetid);
|
||||
await store.dispatch(SET_CURRENT_ACCOUNT, {
|
||||
accountid: to.params.accountid,
|
||||
budgetid: to.params.budgetid
|
||||
});
|
||||
const budgetStore = useBudgetsStore();
|
||||
await budgetStore.SetCurrentBudget((<string>to.params.budgetid));
|
||||
|
||||
const accountStore = useAccountStore();
|
||||
await accountStore.SetCurrentAccount((<string>to.params.budgetid), (<string>to.params.accountid));
|
||||
next();
|
||||
})
|
||||
|
||||
function saveStateToLocalStorage() {
|
||||
const sessionStore = useSessionStore();
|
||||
const budgetStore = useBudgetsStore();
|
||||
const accountStore = useAccountStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
let persistedState = {
|
||||
Session: sessionStore,
|
||||
CurrentBudgetID: budgetStore.CurrentBudgetID,
|
||||
CurrentAccountID: accountStore.CurrentAccountID,
|
||||
ExpandMenu: settingsStore.ExpandMenu,
|
||||
ShowMenu: settingsStore.ShowMenu
|
||||
}
|
||||
localStorage.setItem('store', JSON.stringify(persistedState));
|
||||
|
||||
}
|
||||
|
||||
useSettingsStore().$subscribe(() => saveStateToLocalStorage);
|
||||
useBudgetsStore().$subscribe(() => saveStateToLocalStorage);
|
||||
useSessionStore().$subscribe(() => saveStateToLocalStorage);
|
Reference in New Issue
Block a user