Skip to content

Commit 3b24abf

Browse files
committed
Merge branch 'main' into testimony-count-translations
2 parents d720fd6 + 65fae44 commit 3b24abf

File tree

11 files changed

+68
-241
lines changed

11 files changed

+68
-241
lines changed

components/CurrentCommitteeCard/CurrentCommitteeCard.tsx

Lines changed: 0 additions & 46 deletions
This file was deleted.

components/formatting.tsx

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import { Timestamp } from "firebase/firestore"
2-
import { useMediaQuery } from "usehooks-ts"
3-
import { Testimony } from "../functions/src/testimony/types"
4-
import { Bill, BillContent } from "./db"
5-
61
const billIdFormat = /^(?<chamber>\D+)(?<number>\d+)$/
72

83
/** Formats H123 as H.123 */
@@ -15,56 +10,5 @@ export const formatBillId = (id: string) => {
1510
}
1611
}
1712

18-
const MISSING_TIMESTAMP = Timestamp.fromMillis(0)
19-
export const formatTimestamp = (t?: Timestamp) => {
20-
if (!t || t.toMillis() == MISSING_TIMESTAMP.toMillis()) {
21-
return undefined
22-
}
23-
return t.toDate().toLocaleDateString()
24-
}
25-
26-
export const FormattedBillTitle = ({ bill }: { bill: Bill | BillContent }) => {
27-
const isMobile = useMediaQuery("(max-width: 768px)")
28-
const billInfo = "content" in bill ? bill.content : bill
29-
30-
const { BillNumber, Title } = billInfo
31-
32-
return (
33-
<div className="mt-2">
34-
{formatBillId(BillNumber)}:{" "}
35-
{isMobile ? Title.substring(0, 45) + "..." : Title}
36-
</div>
37-
)
38-
}
39-
40-
export const FormattedTestimonyTitle = ({
41-
testimony
42-
}: {
43-
testimony: Testimony
44-
}) => {
45-
const { authorDisplayName, publishedAt, position } = testimony
46-
47-
return (
48-
<div>
49-
<span>
50-
<b>Author:</b> {authorDisplayName || "anonymous"}
51-
</span>
52-
<br></br>
53-
<span>
54-
<b>Published on:</b> {publishedAt.toDate().toLocaleDateString()}
55-
</span>
56-
<br></br>
57-
<span>
58-
<b>Position:</b> {position}
59-
</span>
60-
</div>
61-
)
62-
}
63-
64-
export const decodeHtmlCharCodes = (s: string) =>
65-
s.replace(/(&#(\d+);)/g, (match, capture, charCode) =>
66-
String.fromCharCode(charCode)
67-
)
68-
6913
export const truncateText = (s: string | undefined, maxLength: number) =>
7014
!!s && s.length > maxLength ? s.substring(0, maxLength) + "..." : s

components/search/bills/BillSearch.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@ import {
77
SearchBox,
88
useInstantSearch
99
} from "react-instantsearch"
10-
import { createInstantSearchRouterNext } from "react-instantsearch-router-nextjs"
11-
import singletonRouter from "next/router"
10+
import { currentGeneralCourt } from "functions/src/shared"
1211
import styled from "styled-components"
1312
import TypesenseInstantSearchAdapter from "typesense-instantsearch-adapter"
14-
import { currentGeneralCourt } from "functions/src/shared"
1513
import { Col, Container, Row, Spinner } from "../../bootstrap"
1614
import { NoResults } from "../NoResults"
1715
import { ResultCount } from "../ResultCount"
1816
import { SearchContainer } from "../SearchContainer"
1917
import { SearchErrorBoundary } from "../SearchErrorBoundary"
18+
import { useRouting } from "../useRouting"
2019
import { BillHit } from "./BillHit"
2120
import { useBillRefinements } from "./useBillRefinements"
2221
import { SortBy, SortByWithConfigurationItem } from "../SortBy"
2322
import { getServerConfig, VirtualFilters } from "../common"
2423
import { useBillSort } from "./useBillSort"
2524
import { FC, useState } from "react"
26-
import { pathToSearchState, searchStateToUrl } from "../routingHelpers"
2725

2826
const searchClient = new TypesenseInstantSearchAdapter({
2927
server: getServerConfig(),
@@ -72,16 +70,8 @@ export const BillSearch = () => {
7270
}
7371
}}
7472
searchClient={searchClient}
75-
routing={{
76-
router: createInstantSearchRouterNext({
77-
singletonRouter,
78-
routerOptions: {
79-
cleanUrlOnDispose: false,
80-
createURL: args => searchStateToUrl(args),
81-
parseURL: args => pathToSearchState(args)
82-
}
83-
})
84-
}}
73+
routing={useRouting()}
74+
future={{ preserveSharedStateOnUnmount: true }}
8575
>
8676
<VirtualFilters type="bill" />
8777
<Layout items={items} />

components/search/routingHelpers.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

components/search/testimony/TestimonySearch.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import {
66
SearchBox,
77
useInstantSearch
88
} from "react-instantsearch"
9-
import { createInstantSearchRouterNext } from "react-instantsearch-router-nextjs"
10-
import singletonRouter from "next/router"
119
import {
1210
StyledTabContent,
1311
StyledTabNav
@@ -25,10 +23,10 @@ import { SearchContainer } from "../SearchContainer"
2523
import { SearchErrorBoundary } from "../SearchErrorBoundary"
2624
import { SortBy } from "../SortBy"
2725
import { getServerConfig, VirtualFilters } from "../common"
26+
import { useRouting } from "../useRouting"
2827
import { TestimonyHit } from "./TestimonyHit"
2928
import { useTestimonyRefinements } from "./useTestimonyRefinements"
3029
import { FollowContext, OrgFollowStatus } from "components/shared/FollowContext"
31-
import { pathToSearchState, searchStateToUrl } from "../routingHelpers"
3230

3331
const searchClient = new TypesenseInstantSearchAdapter({
3432
server: getServerConfig(),
@@ -65,16 +63,8 @@ export const TestimonySearch = () => (
6563
}
6664
}}
6765
searchClient={searchClient}
68-
routing={{
69-
router: createInstantSearchRouterNext({
70-
singletonRouter,
71-
routerOptions: {
72-
cleanUrlOnDispose: false,
73-
createURL: args => searchStateToUrl(args),
74-
parseURL: args => pathToSearchState(args)
75-
}
76-
})
77-
}}
66+
routing={useRouting()}
67+
future={{ preserveSharedStateOnUnmount: true }}
7868
>
7969
<VirtualFilters type="testimony" />
8070
<Layout />

components/search/useRouting.tsx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { UiState } from "instantsearch.js"
2+
import { RouterProps } from "instantsearch.js/es/middlewares"
3+
import Router from "next/router"
4+
import qs from "qs"
5+
import { useMemo } from "react"
6+
7+
const pathToSearchState = (path: string) =>
8+
(path.includes("?")
9+
? qs.parse(path.substring(path.indexOf("?") + 1))
10+
: {}) as UiState
11+
12+
const searchStateToUrl = (searchState: UiState) => {
13+
const base = window.location.pathname
14+
15+
const flagQueries = Object.fromEntries(
16+
Object.entries(qs.parse(window.location.search.slice(1))).filter(
17+
([key]) => !Object.keys(searchState).includes(key)
18+
)
19+
)
20+
21+
const query = qs.stringify({
22+
...searchState,
23+
...flagQueries
24+
})
25+
26+
return query ? `${base}?${query}` : base
27+
}
28+
29+
export function useRouting(): RouterProps<UiState, UiState> {
30+
return useMemo(() => {
31+
let disposed = false
32+
return {
33+
router: {
34+
createURL: searchStateToUrl,
35+
dispose() {
36+
disposed = true
37+
// Clear back listener
38+
Router.beforePopState(() => true)
39+
},
40+
onUpdate(callback) {
41+
Router.beforePopState(({ url }) => {
42+
callback(pathToSearchState(url))
43+
return true
44+
})
45+
},
46+
read: () => pathToSearchState(window.location.href),
47+
write(route) {
48+
if (disposed) return
49+
const url = searchStateToUrl(route)
50+
Router.push(url, url, { shallow: true })
51+
}
52+
}
53+
}
54+
}, [])
55+
}

firestore.rules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ service cloud.firestore {
9999
allow read: if true
100100
allow write: if false
101101
}
102+
103+
// public, read-only
104+
match /paragraphs/{pid} {
105+
allow read: if true
106+
allow write: if false
107+
}
102108
}
103109
}
104110
}

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@
118118
"react-i18next": "^13.2.2",
119119
"react-inlinesvg": "^3.0.1",
120120
"react-instantsearch": "^7.12.4",
121-
"react-instantsearch-router-nextjs": "^7.15.5",
122121
"react-is": "^18.2.0",
123122
"react-markdown": "^8.0.4",
124123
"react-overlays": "^5.1.1",

scripts/stories.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,6 @@ folder: billDetail
156156
grouping: Bill Detail
157157
figmaUrl: https://www.figma.com/file/3ifz37EOwDfmnEG8320KlD/CS1---MAPLE?node-id=180%3A7916
158158
---
159-
name: CurrentCommitteeCard
160-
folder: billDetail
161-
grouping: Bill Detail
162-
figmaUrl: https://www.figma.com/file/3ifz37EOwDfmnEG8320KlD/CS1---MAPLE?node-id=159%3A4939
163-
---
164159
name: BillStatus
165160
folder: billDetail
166161
grouping: Bill Detail

stories/organisms/billDetail/CurrentCommitteeCard.stories.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)