Skip to content

Commit

Permalink
feat: default startDate to undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed Apr 11, 2024
1 parent da5808c commit fcfe54d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions components/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Date>();
const [end, setEnd] = useState<Date>();
const [institution, setInstitution] = useState("Any Institution");
const [min, setMin] = useState(0);
Expand Down
9 changes: 3 additions & 6 deletions components/search/filter/FilterComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,16 @@ export const CustomFilterCheckbox = (props: FilterCheckboxProps) => {
};

interface CalendarFilterProps {
onStartChange: Dispatch<React.SetStateAction<Date>>;
onStartChange: Dispatch<SetStateAction<Date | undefined>>;
onEndChange: Dispatch<SetStateAction<Date | undefined>>;
defaultStart: Date;
defaultStart: Date | undefined;
defaultEnd: Date | undefined;
}

export const CalendarFilter = (props: CalendarFilterProps) => {
const { onStartChange, onEndChange, defaultStart, defaultEnd } = props;

const [startDate, setStartDate] = useState<Date | undefined>(
defaultStart ? new Date(defaultStart) : new Date(),
);
const [startDate, setStartDate] = useState<Date | undefined>(defaultStart);
const [endDate, setEndDate] = useState<Date | undefined>(defaultEnd);

const handleStartChange = (date: Date | undefined) => {
Expand Down Expand Up @@ -138,7 +136,6 @@ export const CalendarFilter = (props: CalendarFilterProps) => {
selected={startDate}
onSelect={handleStartChange}
initialFocus
required
/>
</PopoverContent>
</Popover>
Expand Down
2 changes: 1 addition & 1 deletion components/search/filter/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface SearchFilterProps {
setFormat: Dispatch<SetStateAction<boolean[]>>;
setEnrollment: Dispatch<SetStateAction<boolean[]>>;
setAvailable: Dispatch<SetStateAction<boolean[]>>;
setStart: Dispatch<React.SetStateAction<Date>>;
setStart: Dispatch<React.SetStateAction<Date | undefined>>;
setEnd: Dispatch<SetStateAction<Date | undefined>>;
setInstitution: Dispatch<SetStateAction<string>>;
setMin: Dispatch<SetStateAction<number>>;
Expand Down
8 changes: 6 additions & 2 deletions lib/utils/filter.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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;
}

Expand Down

0 comments on commit fcfe54d

Please sign in to comment.