@@ -2,10 +2,11 @@ import { useTranslation } from "next-i18next"
22import { RefinementList , useInstantSearch } from "react-instantsearch"
33import { faFilter } from "@fortawesome/free-solid-svg-icons"
44import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
5- import { useCallback , useEffect , useState } from "react"
5+ import { useCallback , useState } from "react"
66import styled from "styled-components"
77import { useMediaQuery } from "usehooks-ts"
8- import { Button , Col , Offcanvas } from "../bootstrap"
8+ import { Button , Offcanvas } from "../bootstrap"
9+ import { MultiselectHierarchicalMenu } from "./HierarchicalMenuWidget"
910import { SearchContainer } from "./SearchContainer"
1011
1112export const FilterButton = styled ( Button ) `
@@ -15,15 +16,18 @@ export const FilterButton = styled(Button)`
1516 padding: 0.25rem 0.5rem 0.25rem 0.5rem;
1617 align-self: flex-start;
1718`
19+
1820const useHasRefinements = ( ) => {
1921 const { results } = useInstantSearch ( )
2022 const refinements = results . getRefinements ( )
2123 return refinements . length !== 0
2224}
2325
2426export const useRefinements = ( {
27+ hierarchicalMenuProps,
2528 refinementProps
2629} : {
30+ hierarchicalMenuProps ?: any [ ]
2731 refinementProps : any [ ]
2832} ) => {
2933 const inline = useMediaQuery ( "(min-width: 768px)" )
@@ -38,19 +42,39 @@ export const useRefinements = ({
3842 ) ) }
3943 </ >
4044 )
45+
46+ let hierarchicalMenu = < > </ >
47+
48+ if ( hierarchicalMenuProps ) {
49+ hierarchicalMenu = (
50+ < >
51+ < MultiselectHierarchicalMenu
52+ attributes = { [
53+ hierarchicalMenuProps [ 0 ] . attribute ,
54+ hierarchicalMenuProps [ 1 ] . attribute
55+ ] }
56+ />
57+ </ >
58+ )
59+ }
60+
4161 const hasRefinements = useHasRefinements ( )
4262
4363 const { t } = useTranslation ( "billSearch" )
4464
4565 return {
4666 options : inline ? (
47- < div > { refinements } </ div >
67+ < >
68+ < div > { hierarchicalMenu } </ div >
69+ < div > { refinements } </ div >
70+ </ >
4871 ) : (
4972 < Offcanvas show = { show } onHide = { handleClose } >
5073 < Offcanvas . Header closeButton >
5174 < Offcanvas . Title > { t ( "filter" ) } </ Offcanvas . Title >
5275 </ Offcanvas . Header >
5376 < Offcanvas . Body >
77+ < SearchContainer > { hierarchicalMenu } </ SearchContainer >
5478 < SearchContainer > { refinements } </ SearchContainer >
5579 </ Offcanvas . Body >
5680 </ Offcanvas >
0 commit comments