Speiseplan der Mensen der Georg-August-Universität Göttingen https://mensa.schneider-hosting.de
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

6 years ago
6 years ago
6 years ago
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. const state = {
  5. where: 'zentralmensa',
  6. when: new Date().getDay() || 1,
  7. meals: {},
  8. date: ''
  9. }
  10. const mutations = {
  11. updateWhere(state, where) {
  12. state.where = where
  13. window.localStorage.setItem('mensa_where', where)
  14. },
  15. updateWhen(state, when) {
  16. state.when = when
  17. },
  18. updateMeals(state, meals) {
  19. state.meals = meals
  20. },
  21. updateDate(state, date) {
  22. state.date = date
  23. }
  24. }
  25. const actions = {
  26. /**
  27. * Loads the meals of the desired day and mensa
  28. * @param {Object} payload The payload for this action
  29. * @param {string} payload.where The desired Mensa
  30. * @param {number} payload.when The desired day
  31. */
  32. loadMeals({ commit, state }, payload) {
  33. commit('updateWhere', payload.where)
  34. commit('updateWhen', payload.when)
  35. fetch(`/static/${state.where}.${state.when}.json`)
  36. .then(res => res.json())
  37. .then(menu => {
  38. commit('updateMeals', menu.meals)
  39. commit('updateDate', menu.date)
  40. })
  41. }
  42. }
  43. const getters = {
  44. getWhere(state) {
  45. return state.where
  46. },
  47. getWhen(state) {
  48. return state.when
  49. },
  50. getMeals(state) {
  51. return state.meals
  52. },
  53. getDate(state) {
  54. return state.date
  55. }
  56. }
  57. export default new Vuex.Store({
  58. state,
  59. mutations,
  60. actions,
  61. getters
  62. })