From 87cbd00ac27f58745b23174cb71313e169d82243 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 20 Mar 2023 10:10:33 -0700 Subject: [PATCH] Update how we save and propagate filters We save filterset in a local state, because the FilterBar will send it down to us from cookies. We then set each individual property from that filter set. We set inputs to have a placeholder, as max buttons and max turns could not be set (null). Then, we only send those fields when they have a value provided by the user. --- components/FilterModal/index.tsx | 37 +++++++++++++------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/components/FilterModal/index.tsx b/components/FilterModal/index.tsx index af4537cf..0d79e3e9 100644 --- a/components/FilterModal/index.tsx +++ b/components/FilterModal/index.tsx @@ -26,6 +26,7 @@ import './index.scss' interface Props extends DialogProps { defaultFilterSet: FilterSet filterSet: FilterSet + sendAdvancedFilters: (filters: FilterSet) => void } const MAX_CHARACTERS = 5 @@ -50,7 +51,7 @@ const FilterModal = (props: Props) => { const [fullAutoOpen, setFullAutoOpen] = useState(false) const [autoGuardOpen, setAutoGuardOpen] = useState(false) - const [minCharacterCount, setMinCharacterCount] = useState(3) + const [filterSet, setFilterSet] = useState({}) const [minWeaponCount, setMinWeaponCount] = useState(5) const [minSummonCount, setMinSummonCount] = useState(2) @@ -63,7 +64,6 @@ const FilterModal = (props: Props) => { const [chargeAttack, setChargeAttack] = useState( props.defaultFilterSet.charge_attack ) - const [minCharacterCount, setMinCharacterCount] = useState( props.defaultFilterSet.characters_count ) @@ -125,30 +125,23 @@ const FilterModal = (props: Props) => { } function saveFilters() { - const filters = { - full_auto: fullAuto, - auto_guard: autoGuard, - charge_attack: chargeAttack, - characters_count: minCharacterCount, - weapons_count: minWeaponCount, - summons_count: minSummonCount, - button_count: maxButtonsCount, - turn_count: maxTurnsCount, - name_quality: nameQuality, - user_quality: userQuality, - original: originalOnly, - } + const filters: FilterSet = {} + filters.full_auto = fullAuto + filters.auto_guard = autoGuard + filters.charge_attack = chargeAttack + filters.characters_count = minCharacterCount + filters.weapons_count = minWeaponCount + filters.summons_count = minSummonCount + filters.name_quality = nameQuality + filters.user_quality = userQuality + filters.original = originalOnly - console.log(filters) - 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) - } + if (maxButtonsCount) filters.button_count = maxButtonsCount + if (maxTurnsCount) filters.turn_count = maxTurnsCount setCookie('filters', filters, { path: '/' }) props.sendAdvancedFilters(filters) - // openChange() + openChange() } function resetFilters() {