Fix diverse errors
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import { InjectionKey } from 'vue'
|
||||
import { createStore, Store, createLogger } from 'vuex'
|
||||
import { LOGIN_SUCCESS, LOGOUT, TITLE } from './mutation-types'
|
||||
import { FETCH_ACCOUNT, FETCH_BUDGET, GET, REGISTER, IMPORT_YNAB, LOGIN, NEW_BUDGET, POST, SET_CURRENT_ACCOUNT, SET_CURRENT_BUDGET} from './action-types'
|
||||
import { FETCH_ACCOUNT, FETCH_BUDGET, GET, REGISTER, IMPORT_YNAB, LOGIN, NEW_BUDGET, POST, SET_CURRENT_ACCOUNT, SET_CURRENT_BUDGET } from './action-types'
|
||||
|
||||
export interface State {
|
||||
Session: {
|
||||
@ -32,21 +32,21 @@ export const key: InjectionKey<Store<State>> = Symbol()
|
||||
|
||||
export const store = createStore<State>({
|
||||
state: {
|
||||
Session: {
|
||||
Token: undefined,
|
||||
User: undefined
|
||||
},
|
||||
ShowMenu: undefined,
|
||||
Budgets: new Map<string, Budget>(),
|
||||
CurrentBudgetID: undefined,
|
||||
Accounts: new Map<string, Account>(),
|
||||
CurrentAccountID: undefined,
|
||||
Categories: [],
|
||||
Transactions: [],
|
||||
Assignments: []
|
||||
Session: {
|
||||
Token: undefined,
|
||||
User: undefined
|
||||
},
|
||||
ShowMenu: undefined,
|
||||
Budgets: new Map<string, Budget>(),
|
||||
CurrentBudgetID: undefined,
|
||||
Accounts: new Map<string, Account>(),
|
||||
CurrentAccountID: undefined,
|
||||
Categories: [],
|
||||
Transactions: [],
|
||||
Assignments: []
|
||||
},
|
||||
mutations: {
|
||||
deleteBudget(state : State, budgetid : string) {
|
||||
deleteBudget(state: State, budgetid: string) {
|
||||
state.Budgets.delete(budgetid)
|
||||
},
|
||||
toggleMenu(state) {
|
||||
@ -58,20 +58,20 @@ export const store = createStore<State>({
|
||||
return;
|
||||
|
||||
const restoredState = JSON.parse(store);
|
||||
if(!restoredState)
|
||||
if (!restoredState)
|
||||
return;
|
||||
|
||||
|
||||
state.Session = restoredState.Session;
|
||||
state.CurrentBudgetID= restoredState.CurrentBudgetID;
|
||||
state.CurrentAccountID= restoredState.CurrentAccountID;
|
||||
state.CurrentBudgetID = restoredState.CurrentBudgetID;
|
||||
state.CurrentAccountID = restoredState.CurrentAccountID;
|
||||
state.ShowMenu = restoredState.ShowMenu;
|
||||
|
||||
|
||||
for (const budget of restoredState.Budgets) {
|
||||
state.Budgets.set(budget[0], budget[1]);
|
||||
}
|
||||
}
|
||||
for (const account of restoredState.Accounts) {
|
||||
state.Accounts.set(account[0], account[1]);
|
||||
}
|
||||
}
|
||||
},
|
||||
[TITLE](state, title) {
|
||||
document.title = "Budgeteer - " + title;
|
||||
@ -88,6 +88,9 @@ export const store = createStore<State>({
|
||||
addBudget(state, budget) {
|
||||
state.Budgets.set(budget.ID, budget);
|
||||
},
|
||||
addAccount(state, account) {
|
||||
state.Accounts.set(account.ID, account);
|
||||
},
|
||||
[LOGOUT](state, token) {
|
||||
state.Session = { Token: undefined, User: undefined };
|
||||
state.Budgets.clear();
|
||||
@ -102,9 +105,6 @@ export const store = createStore<State>({
|
||||
setCurrentAccountID(state, accountid) {
|
||||
state.CurrentAccountID = accountid;
|
||||
},
|
||||
setAccounts(state, accounts) {
|
||||
state.Accounts = accounts;
|
||||
},
|
||||
setTransactions(state, transactions) {
|
||||
state.Transactions = transactions;
|
||||
}
|
||||
@ -163,7 +163,9 @@ export const store = createStore<State>({
|
||||
async [FETCH_BUDGET]({ state, commit, dispatch, rootState }, budgetid) {
|
||||
const result = await dispatch("GET", { path: "/budget/" + budgetid });
|
||||
const response = await result.json();
|
||||
return commit("setAccounts", response.Accounts);
|
||||
for (const account of response.Accounts || []) {
|
||||
commit("addAccount", account);
|
||||
}
|
||||
},
|
||||
async [FETCH_ACCOUNT]({ state, commit, rootState }, accountid) {
|
||||
const result = await fetch("/api/v1/account/" + accountid + "/transactions", {
|
||||
|
Reference in New Issue
Block a user