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