diff --git a/components/search/Search.tsx b/components/search/Search.tsx index 3a72136..554ae3b 100644 --- a/components/search/Search.tsx +++ b/components/search/Search.tsx @@ -47,7 +47,7 @@ export type FilterValues = { format: boolean[]; enrollment: boolean[]; available: boolean[]; - start: Date; + start: Date | undefined; end: Date | undefined; institution: string; min: number; @@ -105,8 +105,8 @@ const Search = () => { const [format, setFormat] = useState([true, true]); const [enrollment, setEnrollment] = useState([true]); - const [available, setAvailable] = useState([true]); - const [start, setStart] = useState(new Date()); + const [available, setAvailable] = useState([false]); + const [start, setStart] = useState(); const [end, setEnd] = useState(); const [institution, setInstitution] = useState("Any Institution"); const [min, setMin] = useState(0); diff --git a/components/search/filter/FilterComponents.tsx b/components/search/filter/FilterComponents.tsx index 49e6fae..3a89fe8 100644 --- a/components/search/filter/FilterComponents.tsx +++ b/components/search/filter/FilterComponents.tsx @@ -77,18 +77,16 @@ export const CustomFilterCheckbox = (props: FilterCheckboxProps) => { }; interface CalendarFilterProps { - onStartChange: Dispatch>; + onStartChange: Dispatch>; onEndChange: Dispatch>; - defaultStart: Date; + defaultStart: Date | undefined; defaultEnd: Date | undefined; } export const CalendarFilter = (props: CalendarFilterProps) => { const { onStartChange, onEndChange, defaultStart, defaultEnd } = props; - const [startDate, setStartDate] = useState( - defaultStart ? new Date(defaultStart) : new Date(), - ); + const [startDate, setStartDate] = useState(defaultStart); const [endDate, setEndDate] = useState(defaultEnd); const handleStartChange = (date: Date | undefined) => { @@ -138,7 +136,6 @@ export const CalendarFilter = (props: CalendarFilterProps) => { selected={startDate} onSelect={handleStartChange} initialFocus - required /> diff --git a/components/search/filter/Filters.tsx b/components/search/filter/Filters.tsx index 75a3924..9ab12d7 100644 --- a/components/search/filter/Filters.tsx +++ b/components/search/filter/Filters.tsx @@ -3,7 +3,6 @@ import { CalendarFilter, CustomFilterCheckbox, InstitutionDropdown, - UnitsFilter, } from "./FilterComponents"; import { FaCircleXmark } from "react-icons/fa6"; import { CourseObject, FilterValues } from "../Search"; @@ -13,7 +12,7 @@ interface SearchFilterProps { setFormat: Dispatch>; setEnrollment: Dispatch>; setAvailable: Dispatch>; - setStart: Dispatch>; + setStart: Dispatch>; setEnd: Dispatch>; setInstitution: Dispatch>; setMin: Dispatch>; @@ -25,13 +24,10 @@ interface SearchFilterProps { export const SearchFilters = (props: SearchFilterProps) => { const { setFormat, - setEnrollment, setAvailable, setStart, setEnd, setInstitution, - setMin, - setMax, filterValues, courses, } = props; @@ -44,14 +40,6 @@ export const SearchFilters = (props: SearchFilterProps) => { onChange={setFormat} defaultValue={filterValues.format} /> - { onChange={setInstitution} courses={courses} /> - ); }; diff --git a/lib/utils/filter.ts b/lib/utils/filter.ts index 0a24fce..736e550 100644 --- a/lib/utils/filter.ts +++ b/lib/utils/filter.ts @@ -1,6 +1,10 @@ import { CourseObject, FilterValues } from "../../components/search/Search"; -export const startsAfter = (start: Date, result: CourseObject) => { +export const startsAfter = (start: Date | undefined, result: CourseObject) => { + if (start === undefined) { + return true; + } + const courseDate = new Date(result.startDate); courseDate.setHours(0, 0, 0, 0); @@ -10,7 +14,7 @@ export const startsAfter = (start: Date, result: CourseObject) => { }; export const endsBefore = (end: Date | undefined, result: CourseObject) => { - if (end == undefined) { + if (end === undefined) { return true; }