11import { generalCourts } from "functions/src/shared"
22import { RefinementListItem } from "instantsearch.js/es/connectors/refinement-list/connectRefinementList"
3- import { useCallback } from "react"
3+ import { useMemo } from "react"
44import { useRefinements } from "../useRefinements"
5+ import { useTranslation } from "next-i18next"
56
67// for legacy code purposes, things like:
78//
@@ -17,58 +18,35 @@ import { useRefinements } from "../useRefinements"
1718// searchablePlaceholder: "Legislative Session",
1819
1920export const useBillRefinements = ( ) => {
20- const baseProps = { limit : 500 , searchable : true }
21- const propsList = [
22- {
23- transformItems : useCallback (
24- ( i : RefinementListItem [ ] ) =>
25- i
26- . map ( i => ( {
27- ...i ,
28- label : generalCourts [ i . value as any ] ?. Name ?? i . label
29- } ) )
30- . sort ( ( a , b ) => Number ( b . value ) - Number ( a . value ) ) ,
31- [ ]
32- ) ,
33- attribute : "court" ,
34- searchablePlaceholder : "Legislative Session" ,
35- ...baseProps
36- } ,
37- {
38- attribute : "currentCommittee" ,
39- ...baseProps ,
40- searchablePlaceholder : "Current Committee"
41- } ,
42- {
43- attribute : "city" ,
44- searchablePlaceholder : "City" ,
45- ...baseProps
46- } ,
47- {
48- attribute : "primarySponsor" ,
49- ...baseProps ,
50- searchablePlaceholder : "Primary Sponsor"
51- } ,
52- {
53- attribute : "cosponsors" ,
54- ...baseProps ,
55- searchablePlaceholder : "Cosponsor"
56- }
57- ]
58-
59- const hierarchicalPropsList = [
60- {
61- attribute : "topics.lvl0" ,
62- ...baseProps
63- } ,
64- {
65- attribute : "topics.lvl1" ,
66- ...baseProps
67- }
68- ]
21+ const { t } = useTranslation ( "search" )
6922
7023 return useRefinements ( {
71- hierarchicalMenuProps : hierarchicalPropsList ,
72- refinementProps : propsList
24+ hierarchicalMenuProps : { attributes : [ "topics.lvl0" , "topics.lvl1" ] } ,
25+ refinementProps : useMemo (
26+ ( ) =>
27+ [
28+ {
29+ transformItems : ( items : RefinementListItem [ ] ) =>
30+ items
31+ . map ( i => ( {
32+ ...i ,
33+ label : generalCourts [ parseInt ( i . value , 10 ) ] ?. Name ?? i . label
34+ } ) )
35+ . sort ( ( a , b ) => Number ( b . value ) - Number ( a . value ) ) ,
36+
37+ attribute : "court"
38+ } ,
39+ { attribute : "currentCommittee" } ,
40+ { attribute : "city" } ,
41+ { attribute : "primarySponsor" } ,
42+ { attribute : "cosponsors" }
43+ ] . map ( props => ( {
44+ limit : 500 ,
45+ searchable : true ,
46+ searchablePlaceholder : t ( `refinements.bill.${ props . attribute } ` ) ,
47+ ...props
48+ } ) ) ,
49+ [ t ]
50+ )
7351 } )
7452}
0 commit comments