Skip to content

Commit

Permalink
fix: adjust type for start and end
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed Dec 29, 2023
1 parent bdb23a4 commit 66aaaa3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
9 changes: 6 additions & 3 deletions components/search/blurb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface BlurbProps {
data: CollegeObject[],
filterValues: FilterValues,
) => CollegeObject[];
data: CollegeObject[];
data: CollegeObject[] | undefined;
filterValues: FilterValues;
searchUniversity: string;
searchGE: string;
Expand All @@ -26,10 +26,13 @@ const SearchBlurb = (props: BlurbProps) => {
<div>
We found{" "}
<b className="text-black">
{filterData(data, filterValues).length} courses
{data ? filterData(data, filterValues).length : "x"}
courses
</b>{" "}
that may articulate to{" "}
<b className="text-black">{searchUniversity}</b> for{" "}
<b className="text-black">
{searchUniversity}
</b> for{" "}
<b className="text-black">{`${searchGE?.split(
" ",
)[0]} Category ${searchGE?.split(" ")[1]}`}</b>{" "}
Expand Down
13 changes: 10 additions & 3 deletions components/search/filter-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]) ||
Expand Down
14 changes: 8 additions & 6 deletions components/search/filterComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const CalendarFilter = (props: CalendarFilterProps) => {

interface InstitutionDropdownProps {
defaultValue: string;
courses: CollegeObject[];
courses: CollegeObject[] | undefined;
onChange: Dispatch<SetStateAction<string>>;
}

Expand All @@ -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 (
<div className="relative flex flex-col">
Expand Down
2 changes: 1 addition & 1 deletion components/search/filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface SearchFilterProps {
setMin: Dispatch<SetStateAction<number>>;
setMax: Dispatch<SetStateAction<number>>;
filterValues: FilterValues;
courses: CollegeObject[];
courses: CollegeObject[] | undefined;
}

export const SearchFilters = (props: SearchFilterProps) => {
Expand Down
6 changes: 3 additions & 3 deletions components/search/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,7 +84,7 @@ const Search = () => {

const [sort, setSort] = useState("Default Sort");

const [courses, setCourses] = useState<CollegeObject[]>([]);
const [courses, setCourses] = useState<CollegeObject[]>();

const [filterValues, setFilterValues] = useState<FilterValues>({
format: format,
Expand Down

0 comments on commit 66aaaa3

Please sign in to comment.