Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/legislator/LegislatorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function LegislatorPage(props: { id: string }) {

<Row>
<Col className={`mt-4`} md="9">
<LegislatorTabs />
<LegislatorTabs legislatorId={props.id} />
</Col>
<Col className={`mt-4`} md="3">
<LegislatorSidebar />
Expand Down
6 changes: 4 additions & 2 deletions components/legislator/TabComponents/LegislatorTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ const TabNavItem = ({
}

export function LegislatorTabs({
tabCategory
tabCategory,
legislatorId
}: {
tabCategory?: TabCategories
legislatorId?: string
}) {
const { t } = useTranslation("legislators")

Expand Down Expand Up @@ -98,7 +100,7 @@ export function LegislatorTabs({
{
title: t("tabs.testimony"),
eventKey: "testimony",
content: <Testimony />
content: <Testimony legislatorId={legislatorId} />
},
{
title: t("tabs.votes"),
Expand Down
67 changes: 65 additions & 2 deletions components/legislator/TabComponents/Testimony.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,66 @@
export function Testimony() {
return <div>- Testimony</div>
import { useEffect, useMemo } from "react"
import { useTranslation } from "next-i18next"
import { SmartDisclaimer } from "components/bill/SmartDisclaimer"
import { TestimonyItem } from "components/TestimonyCard/TestimonyItem"
import { usePublishedTestimonyListing } from "components/db/testimony/usePublishedTestimonyListing"
import { CURRENT_COURT_NUMBER } from "components/search/courtSessions"
import { NoResults } from "components/search/NoResults"
import { useAuth } from "components/auth"

export function Testimony({ legislatorId }: { legislatorId?: string }) {
const { t } = useTranslation("testimony")
const { user } = useAuth()

// Query testimonies where legislator is a representative
const representativeTestimony = usePublishedTestimonyListing({
court: CURRENT_COURT_NUMBER
})

// Query testimonies where legislator is a senator
const senatorTestimony = usePublishedTestimonyListing({
court: CURRENT_COURT_NUMBER
})

// Apply legislator filters
useEffect(() => {
if (legislatorId) {
representativeTestimony.setFilter({ representativeId: legislatorId })
}
}, [legislatorId, representativeTestimony])

useEffect(() => {
if (legislatorId) {
senatorTestimony.setFilter({ senatorId: legislatorId })
}
}, [legislatorId, senatorTestimony])

const allTestimonies = useMemo(() => {
const repTestimonies = representativeTestimony.items.result ?? []
const senTestimonies = senatorTestimony.items.result ?? []

// Combine and sort by publishedAt (newest first), then take 4 most recent
return [...repTestimonies, ...senTestimonies]
.sort((a, b) => b.publishedAt.toMillis() - a.publishedAt.toMillis())
.slice(0, 4)
}, [representativeTestimony.items.result, senatorTestimony.items.result])

return (
<>
<SmartDisclaimer />
{allTestimonies.length > 0 ? (
<div>
{allTestimonies.map(testimony => (
<TestimonyItem
key={testimony.id}
testimony={testimony}
isUser={testimony.authorUid === user?.uid}
onProfilePage={true}
/>
))}
</div>
) : (
<NoResults>{t("viewTestimony.noTestimonies")}</NoResults>
)}
</>
)
}