Move store to own folder
This commit is contained in:
26
web/src/store/dashboard/index.js
Normal file
26
web/src/store/dashboard/index.js
Normal file
@ -0,0 +1,26 @@
|
||||
const dashboard = {
|
||||
state () {
|
||||
return {
|
||||
Budgets: [],
|
||||
CurrentBudget: null,
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
setBudgets (state, budgets) {
|
||||
state.Budgets = budgets;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
fetchDashboard ({state, commit, rootState}) {
|
||||
fetch("/api/v1/dashboard", {
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + rootState.Session.Token
|
||||
}
|
||||
})
|
||||
.then(x => x.json())
|
||||
.then(x => commit("setBudgets", x.Budgets));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default dashboard
|
43
web/src/store/index.js
Normal file
43
web/src/store/index.js
Normal file
@ -0,0 +1,43 @@
|
||||
import { createStore } from 'vuex'
|
||||
import dashboard from './dashboard/index.js'
|
||||
|
||||
const store = createStore({
|
||||
state () {
|
||||
return {
|
||||
Session: {
|
||||
Token: null,
|
||||
User: null
|
||||
},
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
initializeStore(state) {
|
||||
let store = localStorage.getItem("store");
|
||||
if(store){
|
||||
this.replaceState(
|
||||
Object.assign(state, JSON.parse(store))
|
||||
);
|
||||
}
|
||||
},
|
||||
setTitle (state, title) {
|
||||
document.title = "Budgeteer - " + title;
|
||||
},
|
||||
setToken(state, token) {
|
||||
state.Session.Token = token;
|
||||
}
|
||||
},
|
||||
modules: {
|
||||
dashboard
|
||||
}
|
||||
})
|
||||
|
||||
store.subscribe((mutation, state) => {
|
||||
let persistedState = {
|
||||
Session: state.Session,
|
||||
Budgets: state.Budgets,
|
||||
CurrentBudget: state.CurrentBudget
|
||||
}
|
||||
localStorage.setItem("store", JSON.stringify(persistedState));
|
||||
})
|
||||
|
||||
export default store
|
Reference in New Issue
Block a user