Skip to content

Commit

Permalink
feat: overhaul filters (#55)
Browse files Browse the repository at this point in the history
* feat: remove unused filters

* feat: default startDate to undefined

* feat: default available seats to false
  • Loading branch information
KevinWu098 authored Apr 11, 2024
1 parent 02a43e9 commit eb1eb37
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
6 changes: 3 additions & 3 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 @@ -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<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
20 changes: 1 addition & 19 deletions components/search/filter/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
CalendarFilter,
CustomFilterCheckbox,
InstitutionDropdown,
UnitsFilter,
} from "./FilterComponents";
import { FaCircleXmark } from "react-icons/fa6";
import { CourseObject, FilterValues } from "../Search";
Expand All @@ -13,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 All @@ -25,13 +24,10 @@ interface SearchFilterProps {
export const SearchFilters = (props: SearchFilterProps) => {
const {
setFormat,
setEnrollment,
setAvailable,
setStart,
setEnd,
setInstitution,
setMin,
setMax,
filterValues,
courses,
} = props;
Expand All @@ -44,14 +40,6 @@ export const SearchFilters = (props: SearchFilterProps) => {
onChange={setFormat}
defaultValue={filterValues.format}
/>
<CustomFilterCheckbox
title="Instant Enrollment"
categories={[
"Only show courses eligible for One-Click Registration between your home school and the teaching school",
]}
onChange={setEnrollment}
defaultValue={filterValues.enrollment}
/>
<CustomFilterCheckbox
title="Available Seats"
categories={[
Expand All @@ -71,12 +59,6 @@ export const SearchFilters = (props: SearchFilterProps) => {
onChange={setInstitution}
courses={courses}
/>
<UnitsFilter
onMinChange={setMin}
onMaxChange={setMax}
defaultMin={filterValues.min}
defaultMax={filterValues.max}
/>
</div>
);
};
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 eb1eb37

Please sign in to comment.