Handle some differences between js/ts
This commit is contained in:
parent
7cba471de7
commit
b350fe7d74
@ -8,6 +8,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -20,6 +20,7 @@ export interface State {
|
||||
|
||||
export interface Budget {
|
||||
ID: string
|
||||
Name: string
|
||||
}
|
||||
|
||||
export interface Account {
|
||||
@ -53,10 +54,23 @@ export const store = createStore<State>({
|
||||
},
|
||||
initializeStore(state) {
|
||||
const store = localStorage.getItem("store");
|
||||
if (store) {
|
||||
this.replaceState(
|
||||
Object.assign(state, JSON.parse(store))
|
||||
);
|
||||
if (!store)
|
||||
return;
|
||||
|
||||
const restoredState = JSON.parse(store);
|
||||
if(!restoredState)
|
||||
return;
|
||||
|
||||
state.Session = restoredState.Session;
|
||||
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) {
|
||||
@ -71,9 +85,6 @@ export const store = createStore<State>({
|
||||
state.Budgets.set(budget.ID, budget)
|
||||
}
|
||||
},
|
||||
setBudgets(state, budgets) {
|
||||
state.Budgets = budgets;
|
||||
},
|
||||
addBudget(state, budget) {
|
||||
state.Budgets.set(budget.ID, budget);
|
||||
},
|
||||
@ -178,7 +189,10 @@ export const store = createStore<State>({
|
||||
},
|
||||
getters: {
|
||||
Budgets(state) {
|
||||
return state.Budgets || [];
|
||||
return state.Budgets.values();
|
||||
},
|
||||
Accounts(state) {
|
||||
return state.Accounts.values();
|
||||
},
|
||||
AuthHeaders(state) {
|
||||
return {
|
||||
@ -189,10 +203,7 @@ export const store = createStore<State>({
|
||||
if (state.CurrentBudgetID == null)
|
||||
return {};
|
||||
|
||||
return state.Budgets.get(state.CurrentBudgetID);
|
||||
},
|
||||
Accounts(state) {
|
||||
return state.Accounts || [];
|
||||
return state.Budgets.get(state.CurrentBudgetID) || {};
|
||||
},
|
||||
CurrentAccount(state) {
|
||||
if (state.CurrentAccountID == null)
|
||||
@ -215,8 +226,8 @@ export const store = createStore<State>({
|
||||
store.subscribe((mutation, state) => {
|
||||
let persistedState = {
|
||||
Session: state.Session,
|
||||
Budgets: state.Budgets,
|
||||
Accounts: state.Accounts,
|
||||
Budgets: [...state.Budgets],
|
||||
Accounts: [...state.Accounts],
|
||||
CurrentBudgetID: state.CurrentBudgetID,
|
||||
CurrentAccountID: state.CurrentAccountID,
|
||||
ShowMenu: state.ShowMenu
|
||||
|
Loading…
x
Reference in New Issue
Block a user