Skip to content

Commit

Permalink
feat: update functions, filters to new schema
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed Apr 3, 2024
1 parent 0c97afc commit 12aef46
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
20 changes: 15 additions & 5 deletions components/search/SearchResults.tsx
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -16,7 +21,10 @@ const SearchResults = (props: SearchResultsProps) => {
<>
<div className="flex flex-col gap-4 md:gap-8">
{results.length > 0 ? (
results.map((result: CollegeObject) => {
results.map((result: CourseObject) => {
const startTime = formatTime(result.startDate);
const endTime = formatTime(result.endDate);

return (
// <LazyLoad
// key={
Expand Down Expand Up @@ -71,15 +79,17 @@ const SearchResults = (props: SearchResultsProps) => {
Term
</div>
<div className="text-base font-light">
{result.term}
{startTime + " - " + endTime}
</div>
</div>
<div className="flex flex-col whitespace-nowrap">
<div className="text-sm font-medium">
GEs
</div>
<div className="flex flex-row gap-2 text-base font-light">
{result.fulfillsGEs.join(", ")}
{result.fulfillsGEs
.map((obj) => obj.category)
.join(", ")}
</div>
</div>
<div className="flex flex-col whitespace-nowrap">
Expand Down
29 changes: 10 additions & 19 deletions lib/utils/filter.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
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);

return courseDate < end;
};

export function filterData(
data: CollegeObject[] | undefined,
data: CourseObject[] | undefined,
filterValues: FilterValues,
) {
if (!data) {
Expand Down Expand Up @@ -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;
})
Expand Down

0 comments on commit 12aef46

Please sign in to comment.