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.

70 lines
1.2 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. },
  14. updateWhen(state, when) {
  15. state.when = when
  16. },
  17. updateMeals(state, meals) {
  18. state.meals = meals
  19. },
  20. updateDate(state, date) {
  21. state.date = date
  22. }
  23. }
  24. const actions = {
  25. /**
  26. * Loads the meals of the desired day and mensa
  27. * @param {Object} payload The payload for this action
  28. * @param {string} payload.where The desired Mensa
  29. * @param {number} payload.when The desired day
  30. */
  31. loadMeals({ commit, state }, payload) {
  32. commit('updateWhere', payload.where)
  33. commit('updateWhen', payload.when)
  34. fetch(`/static/${state.where}.${state.when}.json`)
  35. .then(res => res.json())
  36. .then(menu => {
  37. commit('updateMeals', menu.meals)
  38. commit('updateDate', menu.date)
  39. })
  40. }
  41. }
  42. const getters = {
  43. getWhere(state) {
  44. return state.where
  45. },
  46. getWhen(state) {
  47. return state.when
  48. },
  49. getMeals(state) {
  50. return state.meals
  51. },
  52. getDate(state) {
  53. return state.date
  54. }
  55. }
  56. export default new Vuex.Store({
  57. state,
  58. mutations,
  59. actions,
  60. getters
  61. })