diff --git a/components/FilterBar/index.tsx b/components/FilterBar/index.tsx index b34873ee..adadaf48 100644 --- a/components/FilterBar/index.tsx +++ b/components/FilterBar/index.tsx @@ -1,24 +1,36 @@ import React from 'react' +import { useSnapshot } from 'valtio' import { useTranslation } from 'next-i18next' import classNames from 'classnames' import RaidDropdown from '~components/RaidDropdown' +import { appState } from '~utils/appState' + import './index.scss' interface Props { children: React.ReactNode scrolled: boolean + element?: number + raidSlug?: string + recency?: number onFilter: (element?: number, raid?: string, recency?: number) => void } const FilterBar = (props: Props) => { + // Set up translation const { t } = useTranslation('common') + // Set up state object + const app = useSnapshot(appState) + + // Set up refs for filter dropdowns const elementSelect = React.createRef() const raidSelect = React.createRef() const recencySelect = React.createRef() + // Set up classes object for showing shadow on scroll const classes = classNames({ 'FilterBar': true, 'shadow': props.scrolled @@ -26,8 +38,13 @@ const FilterBar = (props: Props) => { function selectChanged(event: React.ChangeEvent) { const elementValue = (elementSelect.current) ? parseInt(elementSelect.current.value) : -1 - const raidValue = (raidSelect.current) ? raidSelect.current.value : '' const recencyValue = (recencySelect.current) ? parseInt(recencySelect.current.value) : -1 + let raidValue = '' + + if (app.raids) { + const raid = app.raids.find((raid: Raid) => raid.slug === raidSelect.current?.value) + raidValue = (raid) ? raid.id : '' + } props.onFilter(elementValue, raidValue, recencyValue) } @@ -35,19 +52,19 @@ const FilterBar = (props: Props) => { return (
{props.children} - + + + + + + + + { Array.from(Array(sortedRaids?.length)).map((x, i) => renderRaidGroup(i)) }