From 6a0b4d267daaa3ce4dfc67bb1bb60de539960a32 Mon Sep 17 00:00:00 2001 From: Hannah Zhou Date: Sun, 17 Nov 2024 17:12:56 -0500 Subject: [PATCH] potential save course fix - default collection functionality changed - courses in default collection can only be removed by specifically removing that course from the default collection --- src/components/Modals/SaveCourseModal.vue | 5 +++++ src/global-firestore-data/user-semesters.ts | 18 ++++++++++-------- src/store.ts | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/components/Modals/SaveCourseModal.vue b/src/components/Modals/SaveCourseModal.vue index dbea9f591..cb9c9117f 100644 --- a/src/components/Modals/SaveCourseModal.vue +++ b/src/components/Modals/SaveCourseModal.vue @@ -162,6 +162,11 @@ export default defineComponent({ collection => !this.checkedCollections.includes(collection) ); + // If no specific collections were selected, and no prevoius selections were removed, add to 'All' + if (addedToCollections.length === 0 && deletedFromCollections.length === 0) { + console.log('added to All'); + addedToCollections.push('All'); + } this.$emit('save-course', addedToCollections, deletedFromCollections); this.closeCurrentModal(); diff --git a/src/global-firestore-data/user-semesters.ts b/src/global-firestore-data/user-semesters.ts index 06f9d2914..a11180a53 100644 --- a/src/global-firestore-data/user-semesters.ts +++ b/src/global-firestore-data/user-semesters.ts @@ -52,22 +52,24 @@ export const setOrderByNewest = (orderByNewest: boolean): void => { }; /** - * Updates the 'All'/Default Collection with all unique courses from all collections. - * + * Updates the 'All'/Default Collection with courses based on the following logic: + * - Add unique courses from specific collections to the default collection. + * - If a course is removed from the default collection, it is removed from all specific collections. + * Note: Does not remove a course form the default collection if that course is removed in all specfic collections. */ export const editDefaultCollection = (): void => { const allCollections = store.state.savedCourses; const defaultCollectionName = 'All'; - const uniqueCourses = new Set(); + const uniqueCoursesMap = new Map(); allCollections.forEach(collection => { - if (collection.name !== defaultCollectionName) { - collection.courses.forEach(course => { - uniqueCourses.add(course); - }); - } + collection.courses.forEach(course => { + uniqueCoursesMap.set(course.name, course); + }); }); + const uniqueCourses = new Set(uniqueCoursesMap.values()); + editCollection(defaultCollectionName, oldCollection => ({ ...oldCollection, courses: Array.from(uniqueCourses), diff --git a/src/store.ts b/src/store.ts index 750fd8291..c79d87518 100644 --- a/src/store.ts +++ b/src/store.ts @@ -346,7 +346,7 @@ export const initializeFirestoreListeners = (onLoad: () => void): (() => void) = const plan = getFirstPlan(data); store.commit('setPlans', data.plans); store.commit('setCurrentPlan', plan); - store.commit('setSavedCourses', data.savedCourses); // Note: toggle this on and off to save collections progress after refresh + store.commit('setSavedCourses', data.savedCourses); const { orderByNewest } = data; store.commit('setSemesters', plan.semesters); updateDoc(doc(fb.semestersCollection, simplifiedUser.email), { @@ -357,7 +357,7 @@ export const initializeFirestoreListeners = (onLoad: () => void): (() => void) = store.commit('setOrderByNewest', orderByNewest === undefined ? true : orderByNewest); } else { const plans = [{ name: 'Plan 1', semesters: [] }]; - const savedCourses = [{ name: 'All', courses: [] }]; // Warning: Every retruning user needs this Collection too + const savedCourses = [{ name: 'All', courses: [] }]; store.commit('setPlans', plans); store.commit('setCurrentPlan', plans[0]); store.commit('setSavedCourses', savedCourses);