+ Added old store (that doesn't work yet)

This commit is contained in:
Alexis
2021-03-28 18:34:56 +02:00
parent 3713d0cfa0
commit e27e9a2e9e
4 changed files with 69 additions and 77 deletions

View File

@@ -1,50 +1,48 @@
import toastStore from './toasts'
export const state = () => ({
user: {
avatarUrl: '',
favourites: []
}
})
export default {
state: () => ({
user: {
avatarUrl: '',
favourites: []
}
}),
getters: {
// Returns the number of favs for the user
favCount: (state) => {
return state.user.favourites.length
},
// Returns true if celestial is fav
isFav: state => (celestialId) => {
return state.user.favourites.find(fav => fav.id === celestialId)
}
export const getters = {
// Returns the number of favs for the user
favCount: (state) => {
return state.user.favourites.length
},
mutations: {
addFav: (state, celestialId) => {
state.user.favourites.push({ id: celestialId })
},
removeFav: (state, celestialId) => {
state.user.favourites = state.user.favourites.filter(
fav => fav.id !== celestialId
)
}
// Returns true if celestial is fav
isFav: state => (celestialId) => {
return state.user.favourites.find(fav => fav.id === celestialId)
}
}
export const mutations = {
addFav: (state, celestialId) => {
state.user.favourites.push({ id: celestialId })
},
actions: {
toggleFav: ({ commit, getters }, celestialId) => {
// If the celestial is not faved
if (!getters.isFav(celestialId)) {
// ... favs it
commit('addFav', celestialId)
} else {
// ...else unfavs
commit('removeFav', celestialId)
}
}
},
modules: {
toasts: {
namespaced: true,
state: toastStore.state,
mutations: toastStore.mutations,
actions: toastStore.actions
removeFav: (state, celestialId) => {
state.user.favourites = state.user.favourites.filter(
fav => fav.id !== celestialId
)
}
}
export const actions = {
toggleFav: ({ commit, getters }, celestialId) => {
// If the celestial is not faved
if (!getters.isFav(celestialId)) {
// ... favs it
commit('addFav', celestialId)
} else {
// ...else unfavs
commit('removeFav', celestialId)
}
}
}
export default {
state,
getters,
mutations,
actions
}