Remove vuex

This commit is contained in:
2022-02-10 15:49:21 +00:00
parent 8b0e368d58
commit c693625e34
21 changed files with 322 additions and 351 deletions

View File

@ -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);