From 08330ce33ce8dfc837ca8f3e6eb26ce531acf79b Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 9 Feb 2022 23:12:26 +0000 Subject: [PATCH] Migrate farther --- web/src/store/index.ts | 25 ------------------------- web/src/stores/budgets.ts | 16 ++++++++++++++++ web/src/stores/session.ts | 5 +++++ 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/web/src/store/index.ts b/web/src/store/index.ts index 920e664..93775da 100644 --- a/web/src/store/index.ts +++ b/web/src/store/index.ts @@ -59,31 +59,6 @@ export const store = createStore({ await dispatch(FETCH_BUDGET, budgetid) }, }, - getters: { - AuthHeaders(state) { - return { - 'Authorization': 'Bearer ' + state.Session.Token - } - }, - CurrentBudget(state) : Budget | undefined { - if (state.CurrentBudgetID == null) - return undefined; - - return state.Budgets.get(state.CurrentBudgetID); - }, - CurrentBudgetID(state) : string | undefined { - return state.CurrentBudgetID; - }, - CurrentBudgetName(state) : string { - if (state.CurrentBudgetID == null) - return ""; - - const currentBudget = state.Budgets.get(state.CurrentBudgetID); - if(currentBudget != undefined) - return currentBudget.Name; - return ""; - }, - }, plugins: [createLogger()], modules: { budget: budgetStore diff --git a/web/src/stores/budgets.ts b/web/src/stores/budgets.ts index 9e122c9..f0cd8f1 100644 --- a/web/src/stores/budgets.ts +++ b/web/src/stores/budgets.ts @@ -1,4 +1,5 @@ import { defineStore } from "pinia"; +import { Budget, useSessionStore } from "./session"; interface State { CurrentBudgetID: string | null, @@ -12,5 +13,20 @@ export const useBudgetsStore = defineStore('budget', { setCurrentBudgetID(budgetid : string) { this.CurrentBudgetID = budgetid; }, + }, + getters: { + CurrentBudget() : Budget | undefined { + if (this.CurrentBudgetID == null) + return undefined; + + const sessionStore = useSessionStore(); + return sessionStore.Budgets.get(this.CurrentBudgetID); + }, + CurrentBudgetName(state) : string { + return this.CurrentBudget?.Name ?? ""; + }, + CurrentBudgetID() : string | undefined { + return this.CurrentBudgetID; + }, } }) \ No newline at end of file diff --git a/web/src/stores/session.ts b/web/src/stores/session.ts index ad6bdb3..0b5845a 100644 --- a/web/src/stores/session.ts +++ b/web/src/stores/session.ts @@ -23,6 +23,11 @@ export const useSessionStore = defineStore('session', { Budgets(): IterableIterator { return this.Budgets.values(); }, + AuthHeaders(): Object { + return { + 'Authorization': 'Bearer ' + this.Token + } + }, /*// must define return type because of using `this` fullUserDetails (state): FullUserDetails { // import from other stores