diff --git a/web/src/App.vue b/web/src/App.vue
index f92d1d6..fe08b65 100644
--- a/web/src/App.vue
+++ b/web/src/App.vue
@@ -1,7 +1,8 @@
-
diff --git a/web/src/main.js b/web/src/main.js
deleted file mode 100644
index 39e4158..0000000
--- a/web/src/main.js
+++ /dev/null
@@ -1,24 +0,0 @@
-import { createApp } from 'vue/dist/vue.esm-bundler'
-import App from './App.vue'
-import router from './router/routes.js'
-import store from './store/index.js'
-import vuetify from './plugins/vuetify'
-import { loadFonts } from './plugins/webfontloader'
-import { SET_CURRENT_ACCOUNT, SET_CURRENT_BUDGET } from './store/action-types'
-
-loadFonts()
-
-const app = createApp(App)
-app.use(router)
-app.use(store)
-app.use(vuetify)
-app.mount('#app')
-
-router.beforeEach(async (to, from, next) => {
- await store.dispatch(SET_CURRENT_BUDGET, to.params.budgetid);
- await store.dispatch(SET_CURRENT_ACCOUNT, {
- accountid: to.params.accountid,
- budgetid: to.params.budgetid
- });
- next();
-})
diff --git a/web/src/pages/Account.vue b/web/src/pages/Account.vue
index 93ee6e0..1c9b668 100644
--- a/web/src/pages/Account.vue
+++ b/web/src/pages/Account.vue
@@ -1,7 +1,9 @@
-
diff --git a/web/src/pages/BudgetSidebar.vue b/web/src/pages/BudgetSidebar.vue
index 003830e..932cf70 100644
--- a/web/src/pages/BudgetSidebar.vue
+++ b/web/src/pages/BudgetSidebar.vue
@@ -1,7 +1,9 @@
-
diff --git a/web/src/pages/Dashboard.vue b/web/src/pages/Dashboard.vue
index 26e44db..1bfd725 100644
--- a/web/src/pages/Dashboard.vue
+++ b/web/src/pages/Dashboard.vue
@@ -1,10 +1,11 @@
-
diff --git a/web/src/pages/Login.vue b/web/src/pages/Login.vue
index 1a9a6e7..f3905be 100644
--- a/web/src/pages/Login.vue
+++ b/web/src/pages/Login.vue
@@ -1,8 +1,9 @@
-
diff --git a/web/src/pages/Settings.vue b/web/src/pages/Settings.vue
index 431182f..c4006a4 100644
--- a/web/src/pages/Settings.vue
+++ b/web/src/pages/Settings.vue
@@ -1,7 +1,8 @@
-
diff --git a/web/src/router/routes.js b/web/src/router/routes.ts
similarity index 100%
rename from web/src/router/routes.js
rename to web/src/router/routes.ts
diff --git a/web/src/shims-vuex.d.ts b/web/src/shims-vuex.d.ts
new file mode 100644
index 0000000..e442208
--- /dev/null
+++ b/web/src/shims-vuex.d.ts
@@ -0,0 +1,9 @@
+import { ComponentCustomProperties } from 'vue'
+import { State } from './store'
+import { Store } from 'vuex'
+
+declare module '@vue/runtime-core' {
+ interface ComponentCustomProperties {
+ $store: Store
+ }
+}
\ No newline at end of file
diff --git a/web/src/store/action-types.ts b/web/src/store/action-types.ts
new file mode 100644
index 0000000..1914901
--- /dev/null
+++ b/web/src/store/action-types.ts
@@ -0,0 +1,10 @@
+export const IMPORT_YNAB = "YNAB import";
+export const GET = "GET";
+export const POST = "POST";
+export const NEW_BUDGET = "New budget";
+export const SET_CURRENT_BUDGET = "Set current budget";
+export const SET_CURRENT_ACCOUNT = "Set current account";
+export const FETCH_BUDGET = "Fetch budget";
+export const LOGIN = 'Log in';
+export const REGISTER = 'Register';
+export const FETCH_ACCOUNT = "Fetch account";
\ No newline at end of file
diff --git a/web/src/store/index.js b/web/src/store/index.ts
similarity index 79%
rename from web/src/store/index.js
rename to web/src/store/index.ts
index c0d0022..7f2bd19 100644
--- a/web/src/store/index.js
+++ b/web/src/store/index.ts
@@ -1,27 +1,52 @@
-import { createStore, createLogger } from 'vuex'
+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'
-const store = createStore({
- state() {
- return {
+export interface State {
+ Session: {
+ Token?: string
+ User?: string
+ },
+ ShowMenu?: boolean,
+ Budgets: Map,
+ CurrentBudgetID?: string,
+ Accounts: Map,
+ CurrentAccountID?: string,
+ Categories: [],
+ Transactions: [],
+ Assignments: []
+}
+
+export interface Budget {
+ ID: string
+}
+
+export interface Account {
+ ID: string
+ OnBudget: boolean
+}
+
+export const key: InjectionKey> = Symbol()
+
+export const store = createStore({
+ state: {
Session: {
- Token: null,
- User: null
+ Token: undefined,
+ User: undefined
},
- ShowMenu: null,
- Budgets: [],
- CurrentBudgetID: null,
- Accounts: [],
- CurrentAccountID: null,
+ ShowMenu: undefined,
+ Budgets: new Map(),
+ CurrentBudgetID: undefined,
+ Accounts: new Map(),
+ CurrentAccountID: undefined,
Categories: [],
Transactions: [],
Assignments: []
- }
},
mutations: {
- deleteBudget(state, budgetid) {
- delete state.Budgets[budgetid]
+ deleteBudget(state : State, budgetid : string) {
+ state.Budgets.delete(budgetid)
},
toggleMenu(state) {
state.ShowMenu = !state.ShowMenu;
@@ -43,19 +68,19 @@ const store = createStore({
Token: result.Token
};
for (const budget of result.Budgets) {
- state.Budgets[budget.ID] = budget
+ state.Budgets.set(budget.ID, budget)
}
},
setBudgets(state, budgets) {
state.Budgets = budgets;
},
addBudget(state, budget) {
- state.Budgets.push(budget);
+ state.Budgets.set(budget.ID, budget);
},
[LOGOUT](state, token) {
- state.Session = { Token: null, User: null };
- state.Budgets = {};
- state.Accounts = [];
+ state.Session = { Token: undefined, User: undefined };
+ state.Budgets.clear();
+ state.Accounts.clear();
state.Categories = [];
state.Transactions = [];
state.Assignments = [];
@@ -164,7 +189,7 @@ const store = createStore({
if (state.CurrentBudgetID == null)
return {};
- return state.Budgets[state.CurrentBudgetID];
+ return state.Budgets.get(state.CurrentBudgetID);
},
Accounts(state) {
return state.Accounts || [];
@@ -172,13 +197,13 @@ const store = createStore({
CurrentAccount(state) {
if (state.CurrentAccountID == null)
return { name: "Not found" };
- return state.Accounts.filter(x => x.ID == state.CurrentAccountID)[0];
+ return state.Accounts.get(state.CurrentAccountID);
},
OnBudgetAccounts(state) {
- return (state.Accounts || []).filter(x => x.OnBudget);
+ return Array.from(state.Accounts.values()).filter(x => x.OnBudget);
},
OffBudgetAccounts(state) {
- return (state.Accounts || []).filter(x => !x.OnBudget);
+ return Array.from(state.Accounts.values()).filter(x => !x.OnBudget);
},
Transactions(state) {
return (state.Transactions || []);
@@ -197,6 +222,4 @@ store.subscribe((mutation, state) => {
ShowMenu: state.ShowMenu
}
localStorage.setItem("store", JSON.stringify(persistedState));
-})
-
-export default store
\ No newline at end of file
+})
\ No newline at end of file
diff --git a/web/src/store/mutation-types.js b/web/src/store/mutation-types.ts
similarity index 100%
rename from web/src/store/mutation-types.js
rename to web/src/store/mutation-types.ts