+ Added old store (that doesn't work yet)
This commit is contained in:
@@ -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).
|
||||
@@ -1,13 +1,11 @@
|
||||
import toastStore from './toasts'
|
||||
|
||||
export default {
|
||||
state: () => ({
|
||||
export const state = () => ({
|
||||
user: {
|
||||
avatarUrl: '',
|
||||
favourites: []
|
||||
}
|
||||
}),
|
||||
getters: {
|
||||
})
|
||||
|
||||
export const getters = {
|
||||
// Returns the number of favs for the user
|
||||
favCount: (state) => {
|
||||
return state.user.favourites.length
|
||||
@@ -16,8 +14,9 @@ export default {
|
||||
isFav: state => (celestialId) => {
|
||||
return state.user.favourites.find(fav => fav.id === celestialId)
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
addFav: (state, celestialId) => {
|
||||
state.user.favourites.push({ id: celestialId })
|
||||
},
|
||||
@@ -26,8 +25,9 @@ export default {
|
||||
fav => fav.id !== celestialId
|
||||
)
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
toggleFav: ({ commit, getters }, celestialId) => {
|
||||
// If the celestial is not faved
|
||||
if (!getters.isFav(celestialId)) {
|
||||
@@ -38,13 +38,11 @@ export default {
|
||||
commit('removeFav', celestialId)
|
||||
}
|
||||
}
|
||||
},
|
||||
modules: {
|
||||
toasts: {
|
||||
namespaced: true,
|
||||
state: toastStore.state,
|
||||
mutations: toastStore.mutations,
|
||||
actions: toastStore.actions
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
state,
|
||||
getters,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
|
||||
27
full-skies-nuxt/store/toasts.js
Normal file
27
full-skies-nuxt/store/toasts.js
Normal 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
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user