From 66aaaa382a2cdd27a54201bbd28aae141fc02efe Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Fri, 29 Dec 2023 09:57:03 -0800 Subject: [PATCH] fix: adjust type for start and end --- components/search/blurb.tsx | 9 ++++++--- components/search/filter-utils.ts | 13 ++++++++++--- components/search/filterComponents.tsx | 14 ++++++++------ components/search/filters.tsx | 2 +- components/search/search.tsx | 6 +++--- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/components/search/blurb.tsx b/components/search/blurb.tsx index 7699438..c67d818 100644 --- a/components/search/blurb.tsx +++ b/components/search/blurb.tsx @@ -6,7 +6,7 @@ interface BlurbProps { data: CollegeObject[], filterValues: FilterValues, ) => CollegeObject[]; - data: CollegeObject[]; + data: CollegeObject[] | undefined; filterValues: FilterValues; searchUniversity: string; searchGE: string; @@ -26,10 +26,13 @@ const SearchBlurb = (props: BlurbProps) => {
We found{" "} - {filterData(data, filterValues).length} courses + {data ? filterData(data, filterValues).length : "x"} + courses {" "} that may articulate to{" "} - {searchUniversity} for{" "} + + {searchUniversity} + for{" "} {`${searchGE?.split( " ", )[0]} Category ${searchGE?.split(" ")[1]}`}{" "} diff --git a/components/search/filter-utils.ts b/components/search/filter-utils.ts index 8265e08..b4c78a5 100644 --- a/components/search/filter-utils.ts +++ b/components/search/filter-utils.ts @@ -13,8 +13,8 @@ export const startsAfter = ( ); }; -export const endsBefore = (end: string | undefined, result: CollegeObject) => { - if (end == undefined) return true; +export const endsBefore = (end: string, result: CollegeObject) => { + if (end == "") return true; return ( `2024-${result.endMonth.toString().padStart(2, "0")}-${result.endDay @@ -23,7 +23,14 @@ export const endsBefore = (end: string | undefined, result: CollegeObject) => { ); }; -export function filterData(data: CollegeObject[], filterValues: FilterValues) { +export function filterData( + data: CollegeObject[] | undefined, + filterValues: FilterValues, +) { + if (!data) { + return []; + } + const filteredResults = data.filter((result) => { const onlineFormat = (filterValues.format[0] && filterValues.format[1]) || diff --git a/components/search/filterComponents.tsx b/components/search/filterComponents.tsx index d8f3591..9b9819c 100644 --- a/components/search/filterComponents.tsx +++ b/components/search/filterComponents.tsx @@ -118,7 +118,7 @@ export const CalendarFilter = (props: CalendarFilterProps) => { interface InstitutionDropdownProps { defaultValue: string; - courses: CollegeObject[]; + courses: CollegeObject[] | undefined; onChange: Dispatch>; } @@ -139,13 +139,15 @@ export const InstitutionDropdown = (props: InstitutionDropdownProps) => { (course: CollegeObject) => course.sendingInstitution, ); - for (const college of sendingInstitutions) { - if (!uniqueColleges.includes(college)) { - uniqueColleges.push(college); + if (sendingInstitutions) { + for (const college of sendingInstitutions) { + if (!uniqueColleges.includes(college)) { + uniqueColleges.push(college); + } } - } - uniqueColleges.sort(); + uniqueColleges.sort(); + } return (
diff --git a/components/search/filters.tsx b/components/search/filters.tsx index e6f629a..3d1ec19 100644 --- a/components/search/filters.tsx +++ b/components/search/filters.tsx @@ -19,7 +19,7 @@ interface SearchFilterProps { setMin: Dispatch>; setMax: Dispatch>; filterValues: FilterValues; - courses: CollegeObject[]; + courses: CollegeObject[] | undefined; } export const SearchFilters = (props: SearchFilterProps) => { diff --git a/components/search/search.tsx b/components/search/search.tsx index efc5db2..8429343 100644 --- a/components/search/search.tsx +++ b/components/search/search.tsx @@ -43,8 +43,8 @@ export type FilterValues = { format: boolean[]; enrollment: boolean[]; available: boolean[]; - start: string | undefined; - end: string | undefined; + start: string; + end: string; institution: string; min: number; max: number; @@ -84,7 +84,7 @@ const Search = () => { const [sort, setSort] = useState("Default Sort"); - const [courses, setCourses] = useState([]); + const [courses, setCourses] = useState(); const [filterValues, setFilterValues] = useState({ format: format,