Skip to content

Commit

Permalink
Fetch the last 2 academic years' section data for each result (instea…
Browse files Browse the repository at this point in the history
…d of last 1 academic year). In the Spring, when academic year switches, this ensures that the Spring semester is included in most_recent_semester calculations.
  • Loading branch information
AbhiramTadepalli committed Feb 3, 2025
1 parent 6945c34 commit 0cca0ed
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/pages/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function fetchGradesData(
function fetchCourseData(
course: SearchQuery,
controller: AbortController,
): Promise<CourseData> {
): Promise<CourseData[]> {
return fetchWithCache(
'/api/course?prefix=' +
encodeURIComponent(String(course.prefix)) +
Expand All @@ -245,7 +245,7 @@ function fetchCourseData(
})
.then((response: CourseData[]) => {
response.sort((a, b) => b.catalog_year - a.catalog_year); // sort by year descending, so index 0 has the most recent year
return response[0] as CourseData;
return [response[0], response[1]] as CourseData[];
});

controller.abort();
Expand Down Expand Up @@ -280,13 +280,17 @@ function fetchSectionsDataForCourse(
course: SearchQuery,
controller: AbortController,
): Promise<SectionData[]> {
return fetchCourseData(course, controller).then((courseData: CourseData) => {
return Promise.all(
courseData.sections.map((sectionID) =>
fetchSectionData(sectionID, controller),
),
);
});
return fetchCourseData(course, controller).then(
(courseDatas: CourseData[]) => {
return Promise.all(
courseDatas.flatMap((courseData) =>
courseData.sections.map((sectionID) =>
fetchSectionData(sectionID, controller),
),
),
);
},
);
}

//Fetch RMP data from RMP
Expand Down

0 comments on commit 0cca0ed

Please sign in to comment.