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 }) function selectChanged(event: React.ChangeEvent) { const elementValue = (elementSelect.current) ? parseInt(elementSelect.current.value) : -1 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) } return (
{props.children}
) } export default FilterBar