diff --git a/components/LegislatorProfile/LegislatorProfilePage.tsx b/components/LegislatorProfile/LegislatorProfilePage.tsx index e65576a90..000122c27 100644 --- a/components/LegislatorProfile/LegislatorProfilePage.tsx +++ b/components/LegislatorProfile/LegislatorProfilePage.tsx @@ -381,6 +381,7 @@ export function LegislatorProfilePage({ legislatorData={legislatorData} legislatorId={legislatorId} memberCode={memberCode} + sponsoredBills={member.SponsoredBills} /> diff --git a/components/LegislatorProfile/LegislatorSidebar.tsx b/components/LegislatorProfile/LegislatorSidebar.tsx index 155006208..030dbf91e 100644 --- a/components/LegislatorProfile/LegislatorSidebar.tsx +++ b/components/LegislatorProfile/LegislatorSidebar.tsx @@ -9,17 +9,22 @@ export function LegislatorSidebar({ court, legislatorData, legislatorId, - memberCode + memberCode, + sponsoredBills }: { committeeList: any[] court: number legislatorData: any[] legislatorId: string memberCode: string + sponsoredBills?: string[] }) { return ( <> - + ` + font-size: 10px; + font-weight: 600; + text-transform: capitalize; + padding: 1px 6px; + border-radius: 4px; + background-color: ${props => + props.position === "endorse" + ? "#e8f5e9" + : props.position === "oppose" + ? "#ffebee" + : "#f5f5f5"}; + color: ${props => + props.position === "endorse" + ? "#2e7d32" + : props.position === "oppose" + ? "#c62828" + : "#616161"}; +` + +const ContentSnippet = styled.div` + color: #212529; + font-size: 11px; + line-height: 1.4; +` + +const DateLine = styled.div` + color: #8c959f; + font-size: 10px; + margin-top: 4px; +` + +type TestimonyHitRecord = { + id: string + billId: string + court: number + position: "endorse" | "oppose" | "neutral" + content: string + authorDisplayName: string + publishedAt: number +} + +function ConfigureParams({ + court, + billIds +}: { + court: number + billIds: string[] +}) { + const configure = { + hitsPerPage: 3, + filters: `court:=${court} && billId:=[${billIds.join(",")}]` + } as any + useConfigure(configure) + return null +} + +function TestimonyList({ court }: { court: number }) { + const { t } = useTranslation(["legislators", "testimony"]) + const { hits } = useHits() + const { status, results } = useInstantSearch() + + const isLoading = status === "loading" || status === "stalled" || !results._state + + if (isLoading && hits.length === 0) { + return ( +
+ + {t("loading", { defaultValue: "Loading testimony..." })} +
+ ) + } + + if (hits.length === 0) { + return ( +
+ {t("noOtherTestimony", { + defaultValue: "No testimony found for this legislator's bills." + })} +
+ ) + } + + return ( +
+ {hits.map(hit => { + const publishedDate = hit.publishedAt + ? DateTime.fromMillis(hit.publishedAt).toLocaleString( + DateTime.DATE_MED + ) + : null + + return ( + + + + {formatBillId(hit.billId)} + + {hit.position && ( + + {hit.position} + + )} + + + {hit.authorDisplayName || "Anonymous"} + + {hit.content && ( + + + {truncateText(hit.content, 120)} + + + )} + {publishedDate && {publishedDate}} + + ) + })} +
+ ) +} + +export function OtherTestimony({ + court, + sponsoredBills = [] +}: { + court?: number + sponsoredBills?: string[] +}) { const { t } = useTranslation("legislators") + const billIds = useMemo(() => { + return Array.from(new Set(sponsoredBills)) + }, [sponsoredBills]) + + const searchClient = useMemo( + () => + new TypesenseInstantSearchAdapter({ + server: getServerConfig(), + additionalSearchParameters: testimonySearchParams + }).searchClient, + [] + ) + + const courtNumber = court ?? 193 + return ( - {t("otherTestimony")} -
Content To Be Added
+ {t("otherTestimony")} + {billIds.length === 0 ? ( +
+ {t("noOtherTestimony", { + defaultValue: "No testimony found for this legislator's bills." + })} +
+ ) : ( + + + + + )}
) }