diff --git a/nextjs/src/app/CourseList.tsx b/nextjs/src/app/CourseList.tsx index 99137e0..b09af4e 100644 --- a/nextjs/src/app/CourseList.tsx +++ b/nextjs/src/app/CourseList.tsx @@ -1,26 +1,66 @@ "use client"; import { useLocalCoursesSettingsQuery } from "@/hooks/localCourse/localCoursesHooks"; +import { LocalCourseSettings } from "@/models/local/localCourseSettings"; import { getCourseUrl } from "@/services/urlUtils"; import Link from "next/link"; +function getDateKey(dateString: string) { + return dateString.split("T")[0]; +} +function groupByStartDate(courses: LocalCourseSettings[]): { + [key: string]: LocalCourseSettings[]; +} { + return courses.reduce( + (acc, course) => { + const { startDate } = course; + const key = getDateKey(startDate); + if (!acc[key]) { + acc[key] = []; + } + acc[key].push(course); + return acc; + }, + {} as { + [key: string]: LocalCourseSettings[]; + } + ); +} + +function getTermName(startDate: string) { + const [year, month, ...rest] = startDate.split("-"); + if (month < "04") return "Spring " + year; + if (month < "07") return "Summer " + year; + return "Fall " + year; +} + export default function CourseList() { const [allSettings] = useLocalCoursesSettingsQuery(); + const coursesByStartDate = groupByStartDate(allSettings); + return ( -