diff --git a/components/FilterModal/index.tsx b/components/FilterModal/index.tsx index 4e5dfcb6..a4644aa5 100644 --- a/components/FilterModal/index.tsx +++ b/components/FilterModal/index.tsx @@ -46,10 +46,9 @@ const FilterModal = (props: Props) => { // States const [open, setOpen] = useState(false) - - const [fullAuto, setFullAuto] = useState(props.filterSet.full_auto) - const [autoGuard, setAutoGuard] = useState(props.filterSet.auto_guard) - const [chargeAttack, setChargeAttack] = useState(DEFAULT_CHARGE_ATTACK) + const [chargeAttackOpen, setChargeAttackOpen] = useState(false) + const [fullAutoOpen, setFullAutoOpen] = useState(false) + const [autoGuardOpen, setAutoGuardOpen] = useState(false) const [minCharacterCount, setMinCharacterCount] = useState(3) const [minWeaponCount, setMinWeaponCount] = useState(5) @@ -140,7 +139,11 @@ const FilterModal = (props: Props) => { } console.log(filters) - if (maxTurnsCount) filters.turn_count = maxTurnsCount + function openSelect(name: 'charge_attack' | 'full_auto' | 'auto_guard') { + setChargeAttackOpen(name === 'charge_attack' ? !chargeAttackOpen : false) + setFullAutoOpen(name === 'full_auto' ? !fullAutoOpen : false) + setAutoGuardOpen(name === 'auto_guard' ? !autoGuardOpen : false) + } setCookie('filters', filters, { path: '/' }) props.sendAdvancedFilters(filters) @@ -181,19 +184,19 @@ const FilterModal = (props: Props) => { } // Value listeners - function handleChargeAttackValueChange(value: boolean) { - setChargeAttack(value) + function handleChargeAttackValueChange(value: string) { + setChargeAttack(parseInt(value)) } - function handleFullAutoValueChange(value: boolean) { - setFullAuto(value) + function handleFullAutoValueChange(value: string) { + const newValue = parseInt(value) setFullAuto(newValue) if (newValue === 0 || (newValue === -1 && autoGuard === 1)) setAutoGuard(newValue) } - function handleAutoGuardValueChange(value: boolean) { - setAutoGuard(value) + function handleAutoGuardValueChange(value: string) { + const newValue = parseInt(value) setAutoGuard(newValue) if (newValue === 1 || (newValue === -1 && fullAuto === 0)) setFullAuto(newValue) @@ -273,14 +276,14 @@ const FilterModal = (props: Props) => { // Selects const fullAutoField = () => ( - openSelect('full_auto')} onClose={() => setFullAutoOpen(false)} - onValueChange={handleFullAutoValueChange} + onChange={handleFullAutoValueChange} > {t('modals.filters.options.on_and_off')} @@ -291,18 +294,18 @@ const FilterModal = (props: Props) => { {t('modals.filters.options.off')} - /> + ) const autoGuardField = () => ( - openSelect('auto_guard')} onClose={() => setAutoGuardOpen(false)} - onValueChange={handleAutoGuardValueChange} + onChange={handleAutoGuardValueChange} > {t('modals.filters.options.on_and_off')} @@ -313,18 +316,18 @@ const FilterModal = (props: Props) => { {t('modals.filters.options.off')} - /> + ) const chargeAttackField = () => ( - openSelect('charge_attack')} onClose={() => setChargeAttackOpen(false)} - onValueChange={handleChargeAttackValueChange} + onChange={handleChargeAttackValueChange} > {t('modals.filters.options.on_and_off')} @@ -335,7 +338,7 @@ const FilterModal = (props: Props) => { {t('modals.filters.options.off')} - /> + ) // Switches