+ Added favourites page
This commit is contained in:
@@ -103,7 +103,7 @@ export default {
|
|||||||
timer: 3
|
timer: 3
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.$store.dispatch('toggleFav', this.celestial.id)
|
this.$store.dispatch('toggleFav', this.celestial)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,14 +17,10 @@
|
|||||||
export default {
|
export default {
|
||||||
name: 'Favourites',
|
name: 'Favourites',
|
||||||
|
|
||||||
data () {
|
computed: {
|
||||||
return {
|
favourites () {
|
||||||
favourites: []
|
return this.$store.state.user.favourites
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
created () {
|
|
||||||
console.log(this.$store.state.user.favourites)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -17,23 +17,23 @@ export const getters = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
addFav: (state, celestialId) => {
|
addFav: (state, celestial) => {
|
||||||
state.user.favourites.push({ id: celestialId })
|
state.user.favourites.push(celestial)
|
||||||
},
|
},
|
||||||
removeFav: (state, celestialId) => {
|
removeFav: (state, celestial) => {
|
||||||
state.user.favourites = state.user.favourites.filter(
|
state.user.favourites = state.user.favourites.filter(
|
||||||
fav => fav.id !== celestialId
|
fav => fav.id !== celestial.id
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
toggleFav: ({ commit, getters }, celestialId) => {
|
toggleFav: ({ commit, getters }, celestial) => {
|
||||||
// If the celestial is not faved
|
// If the celestial is not faved
|
||||||
if (!getters.isFav(celestialId)) {
|
if (!getters.isFav(celestial.id)) {
|
||||||
commit('addFav', celestialId)
|
commit('addFav', celestial)
|
||||||
} else {
|
} else {
|
||||||
commit('removeFav', celestialId)
|
commit('removeFav', celestial)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user