From fcfe54d64704282bb4e578ffa2acf57d97eb91c0 Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Thu, 11 Apr 2024 16:18:04 -0700 Subject: [PATCH] feat: default startDate to undefined --- components/search/Search.tsx | 4 ++-- components/search/filter/FilterComponents.tsx | 9 +++------ components/search/filter/Filters.tsx | 2 +- lib/utils/filter.ts | 8 ++++++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/components/search/Search.tsx b/components/search/Search.tsx index 3a72136..43ccf1e 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; @@ -106,7 +106,7 @@ 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 [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 1fe8037..9ab12d7 100644 --- a/components/search/filter/Filters.tsx +++ b/components/search/filter/Filters.tsx @@ -12,7 +12,7 @@ interface SearchFilterProps { setFormat: Dispatch>; setEnrollment: Dispatch>; setAvailable: Dispatch>; - setStart: Dispatch>; + setStart: Dispatch>; setEnd: Dispatch>; setInstitution: Dispatch>; setMin: Dispatch>; 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; }