Skip to content

Commit 0cca0ed

Browse files
Fetch the last 2 academic years' section data for each result (instead 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.
1 parent 6945c34 commit 0cca0ed

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Diff for: src/pages/dashboard/index.tsx

+13-9
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ function fetchGradesData(
222222
function fetchCourseData(
223223
course: SearchQuery,
224224
controller: AbortController,
225-
): Promise<CourseData> {
225+
): Promise<CourseData[]> {
226226
return fetchWithCache(
227227
'/api/course?prefix=' +
228228
encodeURIComponent(String(course.prefix)) +
@@ -245,7 +245,7 @@ function fetchCourseData(
245245
})
246246
.then((response: CourseData[]) => {
247247
response.sort((a, b) => b.catalog_year - a.catalog_year); // sort by year descending, so index 0 has the most recent year
248-
return response[0] as CourseData;
248+
return [response[0], response[1]] as CourseData[];
249249
});
250250

251251
controller.abort();
@@ -280,13 +280,17 @@ function fetchSectionsDataForCourse(
280280
course: SearchQuery,
281281
controller: AbortController,
282282
): Promise<SectionData[]> {
283-
return fetchCourseData(course, controller).then((courseData: CourseData) => {
284-
return Promise.all(
285-
courseData.sections.map((sectionID) =>
286-
fetchSectionData(sectionID, controller),
287-
),
288-
);
289-
});
283+
return fetchCourseData(course, controller).then(
284+
(courseDatas: CourseData[]) => {
285+
return Promise.all(
286+
courseDatas.flatMap((courseData) =>
287+
courseData.sections.map((sectionID) =>
288+
fetchSectionData(sectionID, controller),
289+
),
290+
),
291+
);
292+
},
293+
);
290294
}
291295

292296
//Fetch RMP data from RMP

0 commit comments

Comments
 (0)