forked from schneider/mensa
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.3 KiB
71 lines
1.3 KiB
import Vue from 'vue'
|
|
import Vuex from 'vuex'
|
|
|
|
Vue.use(Vuex)
|
|
|
|
const state = {
|
|
where: 'zentralmensa',
|
|
when: new Date().getDay() || 1,
|
|
meals: {},
|
|
date: ''
|
|
}
|
|
|
|
const mutations = {
|
|
updateWhere(state, where) {
|
|
state.where = where
|
|
window.localStorage.setItem('mensa_where', where)
|
|
},
|
|
|
|
updateWhen(state, when) {
|
|
state.when = when
|
|
},
|
|
|
|
updateMeals(state, meals) {
|
|
state.meals = meals
|
|
},
|
|
|
|
updateDate(state, date) {
|
|
state.date = date
|
|
}
|
|
}
|
|
|
|
const actions = {
|
|
/**
|
|
* Loads the meals of the desired day and mensa
|
|
* @param {Object} payload The payload for this action
|
|
* @param {string} payload.where The desired Mensa
|
|
* @param {number} payload.when The desired day
|
|
*/
|
|
loadMeals({ commit, state }, payload) {
|
|
commit('updateWhere', payload.where)
|
|
commit('updateWhen', payload.when)
|
|
fetch(`/static/${state.where}.${state.when}.json`)
|
|
.then(res => res.json())
|
|
.then(menu => {
|
|
commit('updateMeals', menu.meals)
|
|
commit('updateDate', menu.date)
|
|
})
|
|
}
|
|
}
|
|
|
|
const getters = {
|
|
getWhere(state) {
|
|
return state.where
|
|
},
|
|
getWhen(state) {
|
|
return state.when
|
|
},
|
|
getMeals(state) {
|
|
return state.meals
|
|
},
|
|
getDate(state) {
|
|
return state.date
|
|
}
|
|
}
|
|
|
|
export default new Vuex.Store({
|
|
state,
|
|
mutations,
|
|
actions,
|
|
getters
|
|
})
|