Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions frontend/src/components/Toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
PLATFORM_OPTIONS,
SORT_FIELD_OPTIONS,
TAG_OPTIONS,
YEAR_OPTIONS,
} from "../../constants/filterOptions";
import type { GameFilters, SortField, SortState } from "../../types/gameQuery";
import { EMPTY_FILTERS, hasActiveFilters } from "../../types/gameQuery";
Expand Down Expand Up @@ -270,34 +271,48 @@ function FilterPanel({ filters, onApply, onClose }: FilterPanelProps) {

<Form.Group className={styles.field} controlId="yearFrom">
<Form.Label>Released from</Form.Label>
<Form.Control
type="number"
inputMode="numeric"
placeholder="Year"
<Form.Select
value={draft.yearFrom ?? ""}
onChange={(event: ChangeEvent<HTMLInputElement>) =>
onChange={(event: ChangeEvent<HTMLSelectElement>) =>
setDraft((d) => ({
...d,
yearFrom: event.target.value ? Number(event.target.value) : null,
}))
}
/>
>
<option value="">Year</option>
{YEAR_OPTIONS.map((year) => (
<option key={year} value={year}>
{year}
</option>
))}

</Form.Select>
</Form.Group>

<Form.Group className={styles.field} controlId="yearTo">
<Form.Label>Released to</Form.Label>
<Form.Control
type="number"
inputMode="numeric"
placeholder="Year"
<Form.Select
value={draft.yearTo ?? ""}
onChange={(event: ChangeEvent<HTMLInputElement>) =>
onChange={(event: ChangeEvent<HTMLSelectElement>) => {
setDraft((d) => ({
...d,
yearTo: event.target.value ? Number(event.target.value) : null,
}))
}
/>
}}
>
<option value="">Year</option>
{YEAR_OPTIONS.filter(year => {
if (draft.yearFrom == null) return <option key={year}>{year}</option>;
else if (year >= draft.yearFrom) return <option key={year}>{year}</option>;
// If someone changes yearFrom to a later year than yearTo
else if (Number(draft.yearTo) < draft.yearFrom) draft.yearTo = null;
}).map(filterYear => (
<option key={filterYear}>
{filterYear}
</option>
))}
</Form.Select>
</Form.Group>

<Form.Group className={styles.field} controlId="minScore">
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/constants/filterOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ export const ESRB_OPTIONS = [
"Rating Pending",
] as const;

export const YEAR_OPTIONS = [
1984, 1985, 1986, 1987, 1988, 1989,
1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999,
2000, 2001, 2002, 2003, 2004,
2005, 2006, 2007, 2008, 2009,
2010, 2011, 2012, 2013, 2014,
2015, 2016, 2017, 2018, 2019,
2020, // Games imported are only up to 2020
] as const;

export const SORT_FIELD_OPTIONS = [
{ value: "NAME", label: "Name" },
{ value: "RELEASE_DATE", label: "Release date" },
Expand Down