diff --git a/src/components/BottomBar/BottomBarCourseReview.vue b/src/components/BottomBar/BottomBarCourseReview.vue index e8a67cfe9..37b17ac3c 100644 --- a/src/components/BottomBar/BottomBarCourseReview.vue +++ b/src/components/BottomBar/BottomBarCourseReview.vue @@ -119,17 +119,14 @@ export default defineComponent({ return `https://www.cureviews.org/course/${subject}/${number}`; }, CUROverallRating(): string | number { - if (this.courseObj.overallRating === 0) return ''; if (!this.courseObj.overallRating) return 'N/A'; return Math.round(this.courseObj.overallRating * 10) / 10; }, CURDifficulty(): string | number { - if (this.courseObj.difficulty === 0) return ''; if (!this.courseObj.difficulty) return 'N/A'; return Math.round(this.courseObj.difficulty * 10) / 10; }, CURWorkload(): string | number { - if (this.courseObj.workload === 0) return ''; if (!this.courseObj.workload) return 'N/A'; return Math.round(this.courseObj.workload * 10) / 10; }, diff --git a/src/components/BottomBar/BottomBarState.ts b/src/components/BottomBar/BottomBarState.ts index 874440ea3..54898f682 100644 --- a/src/components/BottomBar/BottomBarState.ts +++ b/src/components/BottomBar/BottomBarState.ts @@ -54,18 +54,18 @@ const getReviews = ( method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ subject: subject.toLowerCase(), number }), - }).then(res => - res - .json() - .then(reviews => - reviews.result - ? reviews.result - : { classRating: null, classDifficulty: null, classWorkload: null } - ) + }).then( + res => + (res.ok && res.json().then(reviews => reviews.result)) || { + classRating: null, + classDifficulty: null, + classWorkload: null, + } ); export const addCourseToBottomBar = (course: FirestoreSemesterCourse): void => { vueForBottomBar.isExpanded = true; + for (let i = 0; i < vueForBottomBar.bottomCourses.length; i += 1) { const existingCourse = vueForBottomBar.bottomCourses[i]; // Must check both uniqueID and code (e.g. CS 1110) to handle req courses that share uniqueID -1 @@ -75,32 +75,40 @@ export const addCourseToBottomBar = (course: FirestoreSemesterCourse): void => { } } - if (vueForBottomBar.bottomCourses.length === 0) { - vueForBottomBar.isExpanded = true; - } + vueForBottomBar.bottomCourses = [ + firestoreSemesterCourseToBottomBarCourse(course), + ...vueForBottomBar.bottomCourses, + ]; + vueForBottomBar.bottomCourseFocus = 0; - const bottomBarCourse = firestoreSemesterCourseToBottomBarCourse(course); - const [subject, number] = bottomBarCourse.code.split(' '); + const [subject, number] = course.code.split(' '); Promise.all([ getReviews(subject, number).then(({ classRating, classDifficulty, classWorkload }) => { - bottomBarCourse.overallRating = classRating; - bottomBarCourse.difficulty = classDifficulty; - bottomBarCourse.workload = classWorkload; + const bottomBarCourse = vueForBottomBar.bottomCourses.find( + ({ uniqueID, code }) => uniqueID === course.uniqueID && code === course.code + ); + if (bottomBarCourse) { + bottomBarCourse.overallRating = classRating; + bottomBarCourse.difficulty = classDifficulty; + bottomBarCourse.workload = classWorkload; + } }), getDetailedInformationForBottomBar(course.lastRoster, subject, number).then( ({ description, prereqs, enrollment, lectureTimes, instructors, distributions }) => { - bottomBarCourse.description = description; - bottomBarCourse.prereqs = prereqs; - bottomBarCourse.enrollment = enrollment; - bottomBarCourse.lectureTimes = lectureTimes; - bottomBarCourse.instructors = instructors; - bottomBarCourse.distributions = distributions; + const bottomBarCourse = vueForBottomBar.bottomCourses.find( + ({ uniqueID, code }) => uniqueID === course.uniqueID && code === course.code + ); + if (bottomBarCourse) { + bottomBarCourse.description = description; + bottomBarCourse.prereqs = prereqs; + bottomBarCourse.enrollment = enrollment; + bottomBarCourse.lectureTimes = lectureTimes; + bottomBarCourse.instructors = instructors; + bottomBarCourse.distributions = distributions; + } } ), - ]).then(() => { - vueForBottomBar.bottomCourses = [bottomBarCourse, ...vueForBottomBar.bottomCourses]; - vueForBottomBar.bottomCourseFocus = 0; - }); + ]); }; export const toggleBottomBar = (gtag?: GTag): void => {