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.
 
 
 

53 lines
1.7 KiB

import { BASE_API_URL, getAxiosConfig } from '@/constants'
export const state = () => ({
personal: [],
public: [],
claimed: [],
lastSync: 0
})
export const mutations = {
setPersonal(state, wishes) {
state.personal = wishes
state.lastSync = Date.now()
},
setPublic(state, wishes) {
state.public = wishes
state.lastSync = Date.now()
},
setClaimed(state, wishes) {
state.claimed = wishes
state.lastSync = Date.now()
}
}
export const actions = {
fetchPersonal({ commit }) {
return this.$axios.$get(BASE_API_URL + '/wishes/me', getAxiosConfig(localStorage.getItem("token"))).then(wishes => {
commit('setPersonal', wishes)
})
},
fetchPublic({ commit }) {
return this.$axios.$get(BASE_API_URL + '/wishes/list', getAxiosConfig(localStorage.getItem("token"))).then(wishes => {
commit('setPublic', wishes)
})
},
fetchClaimed({ commit }) {
return this.$axios.$get(BASE_API_URL + '/wishes/claimed', getAxiosConfig(localStorage.getItem("token"))).then(wishes => {
commit('setClaimed', wishes)
})
},
deleteWish({ commit, state }, wishid) {
return this.$axios.$delete(BASE_API_URL + '/wishes/' + wishid, getAxiosConfig(localStorage.getItem("token"))).then(() => {
commit('setPersonal', state.personal.filter(w => w.id !== wishid))
})
},
claimWish({ commit, state }, wishid) {
return this.$axios.$post(BASE_API_URL + '/wishes/' + wishid + '/claim', {}, getAxiosConfig(localStorage.getItem("token"))).then(async () => {
commit('setPublic', state.public.filter(w => w.id !== wishid))
await this.dispatch('wishes/fetchPublic')
await this.dispatch('wishes/fetchClaimed')
})
},
}