Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

potential save course fix #964

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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');

Check warning on line 167 in src/components/Modals/SaveCourseModal.vue

View workflow job for this annotation

GitHub Actions / check

Unexpected console statement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify the functionality:
anytime you save any course, it should end up in the "all" collection, whether you add it to another specific collection or not?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, on a completely separate note, should the other drop downs for collections close if you open a different one? That is, is it possible for all of the collection drop downs to be open at the same time?

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
Loading