Skip to content

Commit 9e20bf4

Browse files
authored
Merge pull request #1780 from kiminkim724/fix-mobile-filters
Fix Mobile Filters
2 parents 42252d0 + daeebe5 commit 9e20bf4

File tree

5 files changed

+57
-30
lines changed

5 files changed

+57
-30
lines changed

components/search/bills/BillSearch.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ import { useRouting } from "../useRouting"
1919
import { BillHit } from "./BillHit"
2020
import { useBillRefinements } from "./useBillRefinements"
2121
import { SortBy, SortByWithConfigurationItem } from "../SortBy"
22-
import { getServerConfig } from "../common"
22+
import { getServerConfig, VirtualFilters } from "../common"
2323
import { useBillSort } from "./useBillSort"
24-
import { useMediaQuery } from "usehooks-ts"
2524
import { FC, useState } from "react"
2625

2726
const searchClient = new TypesenseInstantSearchAdapter({
@@ -72,7 +71,9 @@ export const BillSearch = () => {
7271
}}
7372
searchClient={searchClient}
7473
routing={useRouting()}
74+
future={{ preserveSharedStateOnUnmount: true }}
7575
>
76+
<VirtualFilters type="bill" />
7677
<Layout items={items} />
7778
</InstantSearch>
7879
</SearchErrorBoundary>
@@ -148,16 +149,14 @@ const Layout: FC<
148149

149150
const { t } = useTranslation("billSearch")
150151

151-
const inline = useMediaQuery("(min-width: 768px)")
152-
153152
return (
154153
<SearchContainer>
155154
<Row>
156155
<SearchBox placeholder="Search For Bills" className="mt-2 mb-3" />
157156
</Row>
158157
<Row>
159-
<Col xs={3} lg={3}>
160-
{inline ? refinements.options : null}
158+
<Col xs={0} lg={3}>
159+
{refinements.options}
161160
</Col>
162161
<Col className="d-flex flex-column">
163162
<RefinementRow>

components/search/common.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useRefinementList } from "react-instantsearch"
12
import { TypesenseInstantsearchAdapterOptions } from "typesense-instantsearch-adapter"
23

34
const devConfig = {
@@ -27,3 +28,30 @@ export function getServerConfig(): TypesenseInstantsearchAdapterOptions["server"
2728
]
2829
}
2930
}
31+
32+
function RefinementList({ attribute }: { attribute: string }) {
33+
useRefinementList({ attribute })
34+
return null
35+
}
36+
37+
export function VirtualFilters({ type }: { type: "bill" | "testimony" }) {
38+
const refinementAttributes =
39+
type === "testimony"
40+
? ["authorDisplayName", "court", "position", "billId", "authorRole"]
41+
: [
42+
"court",
43+
"currentCommittee",
44+
"city",
45+
"primarySponsor",
46+
"cosponsors",
47+
"topics.lvl1"
48+
]
49+
50+
return (
51+
<>
52+
{refinementAttributes.map(attribute => (
53+
<RefinementList key={attribute} attribute={attribute} />
54+
))}
55+
</>
56+
)
57+
}

components/search/testimony/TestimonySearch.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { ResultCount } from "../ResultCount"
2222
import { SearchContainer } from "../SearchContainer"
2323
import { SearchErrorBoundary } from "../SearchErrorBoundary"
2424
import { SortBy } from "../SortBy"
25-
import { getServerConfig } from "../common"
25+
import { getServerConfig, VirtualFilters } from "../common"
2626
import { useRouting } from "../useRouting"
2727
import { TestimonyHit } from "./TestimonyHit"
2828
import { useTestimonyRefinements } from "./useTestimonyRefinements"
@@ -64,7 +64,9 @@ export const TestimonySearch = () => (
6464
}}
6565
searchClient={searchClient}
6666
routing={useRouting()}
67+
future={{ preserveSharedStateOnUnmount: true }}
6768
>
69+
<VirtualFilters type="testimony" />
6870
<Layout />
6971
</InstantSearch>
7072
</SearchErrorBoundary>
@@ -149,7 +151,7 @@ const Layout = () => {
149151
/>
150152
</Row>
151153
<Row>
152-
<Col xs={3} lg={3}>
154+
<Col xs={0} lg={3}>
153155
{refinements.options}
154156
</Col>
155157
<Col className="d-flex flex-column">

components/search/useRefinements.tsx

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,25 @@ export const useRefinements = ({
6969
<div>{refinements}</div>
7070
</>
7171
) : (
72-
<>
73-
<div>{hierarchicalMenu}</div>
74-
<div>{refinements}</div>
75-
</>
76-
// <Offcanvas show={show} onHide={handleClose}>
77-
// <Offcanvas.Header closeButton>
78-
// <Offcanvas.Title>{t("filter")}</Offcanvas.Title>
79-
// </Offcanvas.Header>
80-
// <Offcanvas.Body>
81-
// <SearchContainer>{hierarchicalMenu}</SearchContainer>
82-
// <SearchContainer>{refinements}</SearchContainer>
83-
// </Offcanvas.Body>
84-
// </Offcanvas>
72+
<Offcanvas show={show} onHide={handleClose}>
73+
<Offcanvas.Header closeButton>
74+
<Offcanvas.Title>{t("filter")}</Offcanvas.Title>
75+
</Offcanvas.Header>
76+
<Offcanvas.Body>
77+
<SearchContainer>{hierarchicalMenu}</SearchContainer>
78+
<SearchContainer>{refinements}</SearchContainer>
79+
</Offcanvas.Body>
80+
</Offcanvas>
8581
),
86-
show: inline ? null : null
87-
// <FilterButton
88-
// variant="secondary"
89-
// active={show}
90-
// onClick={handleOpen}
91-
// className={hasRefinements ? "ais-FilterButton-has-refinements" : ""}
92-
// >
93-
// <FontAwesomeIcon icon={faFilter} /> {t("filter")}
94-
// </FilterButton>
82+
show: inline ? null : (
83+
<FilterButton
84+
variant="secondary"
85+
active={show}
86+
onClick={handleOpen}
87+
className={hasRefinements ? "ais-FilterButton-has-refinements" : ""}
88+
>
89+
<FontAwesomeIcon icon={faFilter} /> {t("filter")}
90+
</FilterButton>
91+
)
9592
}
9693
}

pages/testimony/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default createPage({
1717

1818
export const getStaticProps = createGetStaticTranslationProps([
1919
"auth",
20+
"billSearch",
2021
"common",
2122
"footer",
2223
"testimony",

0 commit comments

Comments
 (0)