Skip to content

Commit

Permalink
Fix duplicate bottom courses (#560)
Browse files Browse the repository at this point in the history
* fix duplicate bottom courses, add cureviews failsafe

* remove stray import

* fix cureviews n/a
  • Loading branch information
benjamin-shen authored Oct 29, 2021
1 parent fa383c8 commit e6b4e42
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
3 changes: 0 additions & 3 deletions src/components/BottomBar/BottomBarCourseReview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
60 changes: 34 additions & 26 deletions src/components/BottomBar/BottomBarState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 => {
Expand Down

0 comments on commit e6b4e42

Please sign in to comment.