diff --git a/frontend/src/components/Toolbar/Toolbar.tsx b/frontend/src/components/Toolbar/Toolbar.tsx index 29d9caa..4a9fe71 100644 --- a/frontend/src/components/Toolbar/Toolbar.tsx +++ b/frontend/src/components/Toolbar/Toolbar.tsx @@ -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"; @@ -270,34 +271,48 @@ function FilterPanel({ filters, onApply, onClose }: FilterPanelProps) { Released from - ) => + onChange={(event: ChangeEvent) => setDraft((d) => ({ ...d, yearFrom: event.target.value ? Number(event.target.value) : null, })) } - /> + > + + {YEAR_OPTIONS.map((year) => ( + + ))} + + Released to - ) => + onChange={(event: ChangeEvent) => { setDraft((d) => ({ ...d, yearTo: event.target.value ? Number(event.target.value) : null, })) - } - /> + }} + > + + {YEAR_OPTIONS.filter(year => { + if (draft.yearFrom == null) return ; + else if (year >= draft.yearFrom) return ; + // If someone changes yearFrom to a later year than yearTo + else if (Number(draft.yearTo) < draft.yearFrom) draft.yearTo = null; + }).map(filterYear => ( + + ))} + diff --git a/frontend/src/constants/filterOptions.ts b/frontend/src/constants/filterOptions.ts index e876034..e1a968a 100644 --- a/frontend/src/constants/filterOptions.ts +++ b/frontend/src/constants/filterOptions.ts @@ -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" },