Add option for students to mark courses as favorites

This commit is contained in:
2022-11-04 17:43:23 +01:00
parent 45da36cb37
commit 71dab5c590
4 changed files with 128 additions and 31 deletions

View File

@@ -1,3 +1,5 @@
import _pick from 'lodash-es/pick'
export const state = () => ({
firebaseInitialized: false,
idTokenResult: null,
@@ -12,6 +14,10 @@ export const getters = {
},
getCourseByID: (state) => (courseID) => {
return state.courses[courseID]
},
getFavoriteCourses (state) {
// Ref: https://lodash.com/docs/#pick
return _pick(state.courses, state.user.courses)
}
}
@@ -31,6 +37,13 @@ export const mutations = {
setCourses (state, courses) {
state.courses = courses
},
addFavoriteCourse (state, courseID) {
state.user.courses.push(courseID)
},
removeFavoriteCourse (state, courseID) {
const index = state.user.courses.findIndex(e => e === courseID)
state.user.courses.splice(index, 1)
},
setCourse (state, { courseID, courseData }) {
this._vm.$set(state.courses, courseID, courseData)
},