diff --git a/components/legislator/LegislatorPage.tsx b/components/legislator/LegislatorPage.tsx index 35f2b5251..34db79358 100644 --- a/components/legislator/LegislatorPage.tsx +++ b/components/legislator/LegislatorPage.tsx @@ -117,7 +117,7 @@ export function LegislatorPage(props: { id: string }) { - + diff --git a/components/legislator/TabComponents/LegislatorTabs.tsx b/components/legislator/TabComponents/LegislatorTabs.tsx index 34cc14260..9b1caf794 100644 --- a/components/legislator/TabComponents/LegislatorTabs.tsx +++ b/components/legislator/TabComponents/LegislatorTabs.tsx @@ -63,9 +63,11 @@ const TabNavItem = ({ } export function LegislatorTabs({ - tabCategory + tabCategory, + legislatorId }: { tabCategory?: TabCategories + legislatorId?: string }) { const { t } = useTranslation("legislators") @@ -98,7 +100,7 @@ export function LegislatorTabs({ { title: t("tabs.testimony"), eventKey: "testimony", - content: + content: }, { title: t("tabs.votes"), diff --git a/components/legislator/TabComponents/Testimony.tsx b/components/legislator/TabComponents/Testimony.tsx index d69dde353..7e953363c 100644 --- a/components/legislator/TabComponents/Testimony.tsx +++ b/components/legislator/TabComponents/Testimony.tsx @@ -1,3 +1,66 @@ -export function Testimony() { - return
- Testimony
+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 ( + <> + + {allTestimonies.length > 0 ? ( +
+ {allTestimonies.map(testimony => ( + + ))} +
+ ) : ( + {t("viewTestimony.noTestimonies")} + )} + + ) }