diff --git a/components/search/SearchResults.tsx b/components/search/SearchResults.tsx index 61437d7..21b9682 100644 --- a/components/search/SearchResults.tsx +++ b/components/search/SearchResults.tsx @@ -1,10 +1,15 @@ // import LazyLoad from "react-lazy-load"; import { FaUpRightFromSquare } from "react-icons/fa6"; -import { CollegeObject } from "./Search"; +import { CourseObject } from "./Search"; import Tags from "./Tags"; +import { format } from "date-fns"; + +const formatTime = (date: number) => { + return format(new Date(date), "MMM d"); +}; interface SearchResultsProps { - results: CollegeObject[]; + results: CourseObject[]; university: string; ge: string; } @@ -16,7 +21,10 @@ const SearchResults = (props: SearchResultsProps) => { <>
{results.length > 0 ? ( - results.map((result: CollegeObject) => { + results.map((result: CourseObject) => { + const startTime = formatTime(result.startDate); + const endTime = formatTime(result.endDate); + return ( // { Term
- {result.term} + {startTime + " - " + endTime}
@@ -79,7 +87,9 @@ const SearchResults = (props: SearchResultsProps) => { GEs
- {result.fulfillsGEs.join(", ")} + {result.fulfillsGEs + .map((obj) => obj.category) + .join(", ")}
diff --git a/lib/utils/filter.ts b/lib/utils/filter.ts index 5f6ce7c..0a24fce 100644 --- a/lib/utils/filter.ts +++ b/lib/utils/filter.ts @@ -1,23 +1,21 @@ -import { CollegeObject, FilterValues } from "../../components/search/Search"; +import { CourseObject, FilterValues } from "../../components/search/Search"; + +export const startsAfter = (start: Date, result: CourseObject) => { + const courseDate = new Date(result.startDate); -export const startsAfter = (start: Date, result: CollegeObject) => { - const month = result.startMonth.toString().padStart(2, "0"); - const day = result.startDay.toString().padStart(2, "0"); - const courseDate = new Date(`2024-${month}-${day}`); courseDate.setHours(0, 0, 0, 0); courseDate.setDate(courseDate.getDate() + 1); return courseDate > start; }; -export const endsBefore = (end: Date | undefined, result: CollegeObject) => { +export const endsBefore = (end: Date | undefined, result: CourseObject) => { if (end == undefined) { return true; } - const month = result.endMonth.toString().padStart(2, "0"); - const day = result.endDay.toString().padStart(2, "0"); - const courseDate = new Date(`2024-${month}-${day}`); + const courseDate = new Date(result.endDate); + courseDate.setHours(0, 0, 0, 0); courseDate.setDate(courseDate.getDate() + 1); @@ -25,7 +23,7 @@ export const endsBefore = (end: Date | undefined, result: CollegeObject) => { }; export function filterData( - data: CollegeObject[] | undefined, + data: CourseObject[] | undefined, filterValues: FilterValues, ) { if (!data) { @@ -78,15 +76,8 @@ export function filterData( }) : filterValues.sort == "Shortest Term" ? filteredResults.sort((courseA, courseB) => { - const termLengthA = - ((courseA.endMonth - courseA.startMonth + 12) % 12) * - 30 + - (courseA.endDay - courseA.startDay); - - const termLengthB = - ((courseB.endMonth - courseB.startMonth + 12) % 12) * - 30 + - (courseB.endDay - courseB.startDay); + const termLengthA = courseA.endDate - courseA.startDate; + const termLengthB = courseB.endDate - courseB.startDate; return termLengthA - termLengthB; })