Skip to content

Commit

Permalink
potential save course fix
Browse files Browse the repository at this point in the history
- default collection functionality changed
- courses in default collection can only be removed by specifically removing that course from the default collection
  • Loading branch information
plumshum committed Nov 17, 2024
1 parent 275203e commit 6a0b4d2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/components/Modals/SaveCourseModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 10 additions & 8 deletions src/global-firestore-data/user-semesters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FirestoreSemesterCourse>();
const uniqueCoursesMap = new Map<string, FirestoreSemesterCourse>();
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<FirestoreSemesterCourse>(uniqueCoursesMap.values());

editCollection(defaultCollectionName, oldCollection => ({
...oldCollection,
courses: Array.from(uniqueCourses),
Expand Down
4 changes: 2 additions & 2 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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), {
Expand All @@ -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);
Expand Down

0 comments on commit 6a0b4d2

Please sign in to comment.