Make filter for isResolved work in all cases
This commit is contained in:
parent
e9fee04761
commit
1616ffc817
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
import algoliasearch from 'algoliasearch/lite'
|
import algoliasearch from 'algoliasearch/lite'
|
||||||
import {
|
import {
|
||||||
InstantSearch,
|
InstantSearch,
|
||||||
|
@ -8,7 +9,6 @@ import {
|
||||||
useRange,
|
useRange,
|
||||||
useRefinementList,
|
useRefinementList,
|
||||||
useSortBy,
|
useSortBy,
|
||||||
useToggleRefinement,
|
|
||||||
} from 'react-instantsearch-hooks-web'
|
} from 'react-instantsearch-hooks-web'
|
||||||
import { Contract } from '../../common/contract'
|
import { Contract } from '../../common/contract'
|
||||||
import {
|
import {
|
||||||
|
@ -237,13 +237,16 @@ const useFilterClosed = (value: boolean | undefined) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const useFilterResolved = (value: boolean | undefined) => {
|
const useFilterResolved = (value: boolean | undefined) => {
|
||||||
// Note (James): I don't know why this works.
|
const { items, refine: deleteRefinement } = useCurrentRefinements({
|
||||||
const { refine: refineResolved } = useToggleRefinement({
|
includedAttributes: ['isResolved'],
|
||||||
attribute: value === undefined ? 'non-existant-field' : 'isResolved',
|
|
||||||
on: true,
|
|
||||||
off: value === undefined ? undefined : false,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const { refine } = useRefinementList({ attribute: 'isResolved' })
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refineResolved({ isRefined: !value })
|
const refinements = items[0]?.refinements ?? []
|
||||||
|
|
||||||
|
if (value !== undefined) refine(`${value}`)
|
||||||
|
refinements.forEach((refinement) => deleteRefinement(refinement))
|
||||||
}, [value])
|
}, [value])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user