Migrate farther

This commit is contained in:
Jan Bader 2022-02-09 23:12:26 +00:00
parent 2d0737a10c
commit 08330ce33c
3 changed files with 21 additions and 25 deletions

View File

@ -59,31 +59,6 @@ export const store = createStore<State>({
await dispatch(FETCH_BUDGET, budgetid) 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()], plugins: [createLogger()],
modules: { modules: {
budget: budgetStore budget: budgetStore

View File

@ -1,4 +1,5 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { Budget, useSessionStore } from "./session";
interface State { interface State {
CurrentBudgetID: string | null, CurrentBudgetID: string | null,
@ -12,5 +13,20 @@ export const useBudgetsStore = defineStore('budget', {
setCurrentBudgetID(budgetid : string) { setCurrentBudgetID(budgetid : string) {
this.CurrentBudgetID = budgetid; 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;
},
} }
}) })

View File

@ -23,6 +23,11 @@ export const useSessionStore = defineStore('session', {
Budgets(): IterableIterator<Budget> { Budgets(): IterableIterator<Budget> {
return this.Budgets.values(); return this.Budgets.values();
}, },
AuthHeaders(): Object {
return {
'Authorization': 'Bearer ' + this.Token
}
},
/*// must define return type because of using `this` /*// must define return type because of using `this`
fullUserDetails (state): FullUserDetails { fullUserDetails (state): FullUserDetails {
// import from other stores // import from other stores