+ 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,10 +0,0 @@
# STORE
**This directory is not required, you can delete it if you don't want to use it.**
This directory contains your Vuex Store files.
Vuex Store option is implemented in the Nuxt.js framework.
Creating a file in this directory automatically activates the option in the framework.
More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/vuex-store).

View File

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

View File

@@ -0,0 +1,27 @@
export const state = () => ({
queue: []
})
export const mutations = {
pushToast: (state, toast) => {
state.queue.push(toast)
},
purgeToast: (state, toastId) => {
state.queue = state.queue.filter(toast => toast.id !== toastId)
}
}
export const actions = {
pushToast: ({ commit }, toast) => {
commit('pushToast', toast)
},
purgeToast: ({ commit }, toastId) => {
commit('purgeToast', toastId)
}
}
export default {
state,
mutations,
actions
}

View File

@@ -1,23 +0,0 @@
export default {
state: () => {
return {
queue: []
}
},
mutations: {
pushToast: (state, toast) => {
state.queue.push(toast)
},
purgeToast: (state, toastId) => {
state.queue = state.queue.filter(toast => toast.id !== toastId)
}
},
actions: {
pushToast: ({ commit }, toast) => {
commit('pushToast', toast)
},
purgeToast: ({ commit }, toastId) => {
commit('purgeToast', toastId)
}
}
}