Skip to content

Commit 42252d0

Browse files
authored
Merge pull request #1751 from seatuna/ctoon/1730/page-load-performance
feat(1760): add loading spinner when navigating to bill details
2 parents 4f65905 + ca517f2 commit 42252d0

File tree

3 files changed

+45
-26
lines changed

3 files changed

+45
-26
lines changed

components/bill/BillDetails.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,11 @@ import { useTranslation } from "next-i18next"
1717
import { isCurrentCourt } from "functions/src/shared"
1818
import { FollowBillButton } from "components/shared/FollowButton"
1919
import { PendingUpgradeBanner } from "components/PendingUpgradeBanner"
20-
import { FollowContext, OrgFollowStatus } from "components/shared/FollowContext"
21-
import { useState } from "react"
2220

2321
const StyledContainer = styled(Container)`
2422
font-family: "Nunito";
2523
`
2624

27-
const StyledImage = styled(Image)`
28-
width: 14.77px;
29-
height: 12.66px;
30-
31-
margin-left: 8px;
32-
`
33-
3425
export const BillDetails = ({ bill }: BillProps) => {
3526
const { t } = useTranslation("common")
3627

components/search/bills/BillHit.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import styled from "styled-components"
1313
import { Card, Col } from "../../bootstrap"
1414
import { formatBillId } from "../../formatting"
1515
import { Timestamp } from "firebase/firestore"
16-
import { DateTime } from "luxon"
1716
import { dateInFuture } from "components/db/events"
1817

1918
type BillRecord = {
@@ -132,11 +131,7 @@ export const DisplayUpcomingHearing = ({
132131

133132
export const BillHit = ({ hit }: { hit: Hit<BillRecord> }) => {
134133
const url = maple.bill({ id: hit.number, court: hit.court })
135-
const today = new Date()
136134
const hearingDate = hit.nextHearingAt && hit.nextHearingAt / 1000 // convert to seconds
137-
const isUpcomingHearing = hearingDate
138-
? today < fromUnixTime(hearingDate)
139-
: false
140135

141136
return (
142137
<Link href={url} legacyBehavior>

components/search/bills/BillSearch.tsx

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useTranslation } from "next-i18next"
1+
import { TFunction, useTranslation } from "next-i18next"
22
import {
33
CurrentRefinements,
44
Hits,
@@ -10,7 +10,7 @@ import {
1010
import { currentGeneralCourt } from "functions/src/shared"
1111
import styled from "styled-components"
1212
import TypesenseInstantSearchAdapter from "typesense-instantsearch-adapter"
13-
import { Col, Row } from "../../bootstrap"
13+
import { Col, Container, Row, Spinner } from "../../bootstrap"
1414
import { NoResults } from "../NoResults"
1515
import { ResultCount } from "../ResultCount"
1616
import { SearchContainer } from "../SearchContainer"
@@ -21,8 +21,8 @@ import { useBillRefinements } from "./useBillRefinements"
2121
import { SortBy, SortByWithConfigurationItem } from "../SortBy"
2222
import { getServerConfig } from "../common"
2323
import { useBillSort } from "./useBillSort"
24-
import { FC } from "react"
2524
import { useMediaQuery } from "usehooks-ts"
25+
import { FC, useState } from "react"
2626

2727
const searchClient = new TypesenseInstantSearchAdapter({
2828
server: getServerConfig(),
@@ -99,6 +99,47 @@ const useSearchStatus = () => {
9999
}
100100
}
101101

102+
const StyledLoadingContainer = styled(Container)`
103+
background-color: white;
104+
display: flex;
105+
height: 300px;
106+
justify-content: center;
107+
align-items: center;
108+
`
109+
110+
const Results = ({
111+
status,
112+
t
113+
}: {
114+
status: ReturnType<typeof useSearchStatus>
115+
t: TFunction
116+
}) => {
117+
const [isLoadingBillDetails, setIsLoadingBillDetails] = useState(false)
118+
119+
if (isLoadingBillDetails) {
120+
return (
121+
<StyledLoadingContainer>
122+
<Spinner animation="border" className="mx-auto" />
123+
</StyledLoadingContainer>
124+
)
125+
} else if (status === "empty") {
126+
return (
127+
<NoResults>
128+
{t("zero_results")}
129+
<br />
130+
<b>{t("another_term")}</b>
131+
</NoResults>
132+
)
133+
} else {
134+
return (
135+
<Hits
136+
hitComponent={BillHit}
137+
onClick={() => setIsLoadingBillDetails(true)}
138+
/>
139+
)
140+
}
141+
}
142+
102143
const Layout: FC<
103144
React.PropsWithChildren<{ items: SortByWithConfigurationItem[] }>
104145
> = ({ items }) => {
@@ -129,15 +170,7 @@ const Layout: FC<
129170
excludedAttributes={["nextHearingAt"]}
130171
transformItems={extractLastSegmentOfRefinements}
131172
/>
132-
{status === "empty" ? (
133-
<NoResults>
134-
{t("zero_results")}
135-
<br />
136-
<b>{t("another_term")}</b>
137-
</NoResults>
138-
) : (
139-
<Hits hitComponent={BillHit} />
140-
)}
173+
<Results status={status} t={t} />
141174
<Pagination className="mx-auto mt-2 mb-3" />
142175
</Col>
143176
</Row>

0 commit comments

Comments
 (0)