Skip to content

Commit

Permalink
Removing individual filters quickly (#221)
Browse files Browse the repository at this point in the history
Fixes #202
  • Loading branch information
andrew-codes authored Feb 19, 2024
2 parents 3643f6e + 59b91d5 commit 010809d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps/playnite-web/src/components/Filters/FilterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ const filterFormReducer = (state, action) => {
...state,
['nameFilter']: action.payload,
}
case 'removeFilter':
return {
...state,
[`${state.filterBy}Filter`]: state[`${state.filterBy}Filter`].filter(
(filter) => filter.id !== action.payload,
),
}
case 'reset':
return action.payload
case 'clear':
Expand Down Expand Up @@ -118,6 +125,9 @@ const FilterForm: FC<{
payload: values,
})
}, [])
const handleRemoveFilter = (filterId: string) => {
dispatch({ type: 'removeFilter', payload: filterId })
}

const handleResetFilters = useCallback(
(evt: React.FormEvent<HTMLFormElement>) => {
Expand Down Expand Up @@ -161,6 +171,7 @@ const FilterForm: FC<{
<Fragment key={filter.id}>
<Chip
label={filter.name}
onDelete={() => handleRemoveFilter(filter.id)}
sx={(theme) => ({ margin: theme.spacing(0.25) })}
/>
<input type="hidden" name="platformFilter" value={filter.id} />
Expand All @@ -170,6 +181,7 @@ const FilterForm: FC<{
<Fragment key={filter.id}>
<Chip
label={filter.name}
onDelete={() => handleRemoveFilter(filter.id)}
sx={(theme) => ({ margin: theme.spacing(0.25) })}
/>
<input type="hidden" name="featureFilter" value={filter.id} />
Expand Down

0 comments on commit 010809d

Please sign in to comment.