diff --git a/components/EditProfilePage/FollowersTab.tsx b/components/EditProfilePage/FollowersTab.tsx index b03561bed..e1e622396 100644 --- a/components/EditProfilePage/FollowersTab.tsx +++ b/components/EditProfilePage/FollowersTab.tsx @@ -47,6 +47,7 @@ export const FollowersTab = ({ }) } } + useEffect(() => { if (uid) { setState(prev => ({ ...prev, loading: true, error: null })) @@ -55,6 +56,7 @@ export const FollowersTab = ({ setState({ items: [], loading: false, error: null }) } }, [uid]) + return ( diff --git a/components/LegislatorProfile/LegislatorSidebar.tsx b/components/LegislatorProfile/LegislatorSidebar.tsx index 155006208..e77171fdb 100644 --- a/components/LegislatorProfile/LegislatorSidebar.tsx +++ b/components/LegislatorProfile/LegislatorSidebar.tsx @@ -1,5 +1,7 @@ import styled from "styled-components" +import * as links from "../links" + import { Biography } from "./SidebarComponents/Biography" import { OtherTestimony } from "./SidebarComponents/OtherTestimony" import { UpcomingHearings } from "./SidebarComponents/UpcomingHearings" @@ -9,17 +11,19 @@ export function LegislatorSidebar({ court, legislatorData, legislatorId, - memberCode + memberCode, + sponsoredBills }: { committeeList: any[] court: number legislatorData: any[] legislatorId: string memberCode: string + sponsoredBills?: string[] }) { return ( <> - + ({ + className: `${props.className}` +}))` + background: #d4edda; + color: #155724; + + font-size: 10px; + font-weight: 700; + padding: 2px 7px; + border-radius: 999px; + margin-bottom: 4px; + display: inline-block; +` + +const NeutralBubble = styled.div.attrs(props => ({ + className: `${props.className}` +}))` + background: #d1d6e7; + color: #1a3185; + + font-size: 10px; + font-weight: 700; + padding: 2px 7px; + border-radius: 999px; + margin-bottom: 4px; + display: inline-block; +` + +const OpposeBubble = styled.div.attrs(props => ({ + className: `${props.className}` +}))` + background: #f4d2d6; + color: #8b0000; + + font-size: 10px; + font-weight: 700; + padding: 2px 7px; + border-radius: 999px; + margin-bottom: 4px; + display: inline-block; +` + +function PositionButton(props: { position: string }) { const { t } = useTranslation("legislators") + switch (props.position) { + case "endorse": + return {t("position.endorse")} + case "oppose": + return {t("position.oppose")} + default: + return {t("position.neutral")} + } +} + +/* Misc Testimony Components */ + +const BillLink = styled(Internal)` + font-weight: 700; + color: #1a3185; + text-decoration: none; + + &:hover { + text-decoration: underline; + } +` + +const ContentSnippet = styled.div` + color: #212529; + font-size: 11px; + line-height: 1.4; +` + +const DateLine = styled.span` + whitespace: "nowrap"; +` + +const Interpunct = styled.span` + color: #3b3b3b; + font-weight: 700; +` + +const TestimonyBorder = styled.div` + border-bottom: 1px solid #b8c0c9; +` + +const TestimonyMeta = styled.div` + color: #6c757d; + font-size: 10px; +` + +const TestimonyText = styled.div` + color: #495057; + line-height: 1.5; + font-size: 12px; + font-style: italic; + margin-bottom: 3px; +` + +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("noTestimony", { + 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 ( + + + + {hit.content && ( + + + {truncateText(hit.content, 120)} + + + )} + + + {hit.authorDisplayName || "Anonymous"} + {" · "} + + {formatBillId(hit.billId)} + + {" · "} + + {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("noTestimony", { + defaultValue: "No testimony found for this legislator's bills." + })} +
+ ) : ( + <> + + + + + + + + {t("viewAllTestimony")} + {" ↗"} + + + + )}
) } diff --git a/components/LegislatorProfile/SidebarComponents/UpcomingHearings.tsx b/components/LegislatorProfile/SidebarComponents/UpcomingHearings.tsx index 4bbb86c2e..72e9bbdc2 100644 --- a/components/LegislatorProfile/SidebarComponents/UpcomingHearings.tsx +++ b/components/LegislatorProfile/SidebarComponents/UpcomingHearings.tsx @@ -2,9 +2,8 @@ import { DateTime } from "luxon" import { useTranslation } from "next-i18next" import styled from "styled-components" -import * as links from "../../links" import { Col } from "../../bootstrap" -import { SidebarBlock, SidebarTitle } from "../LegislatorSidebar" +import { SidebarBlock, SidebarLink, SidebarTitle } from "../LegislatorSidebar" import { useUpcomingEvents } from "components/db/events" import { EventData } from "components/HearingsScheduled" @@ -33,16 +32,6 @@ const EventLocation = styled.div` margin-top: 1px; ` -export const HearingsLink = styled(links.Internal)` - font-size: 12px; - font-weight: 700; - color: #1a3185; - padding: 10px; - display: block; - text-align: center; - text-decoration: none; -` - export function UpcomingHearings({ committeeList }: { committeeList: any[] }) { const { t } = useTranslation("legislators") @@ -78,20 +67,18 @@ export function UpcomingHearings({ committeeList }: { committeeList: any[] }) { } } - const LegislatorCommitteCodes = committeeList.map(code => code.CommitteeCode) + const LegislatorCommitteeCodes = committeeList.map(code => code.CommitteeCode) let legislatorEvents: any[] = [] if (events) { eventList.forEach(event => { - if (LegislatorCommitteCodes.includes(event.code)) { + if (LegislatorCommitteeCodes.includes(event.code)) { legislatorEvents.push(event) } }) } - console.log("legislatorEvents", legislatorEvents) - return ( {t("upcomingHearings")} @@ -111,10 +98,10 @@ export function UpcomingHearings({ committeeList }: { committeeList: any[] }) {
{t("noEvents")}
)} - + {t("viewAllHearings")} {" ↗"} - +
) diff --git a/public/locales/en/legislators.json b/public/locales/en/legislators.json index 7e7f142f0..8c3a21ae9 100644 --- a/public/locales/en/legislators.json +++ b/public/locales/en/legislators.json @@ -45,6 +45,7 @@ "legislators": "Legislators", "loading": "Loading district...", "noEvents": "This legislator does not have hearings in the near term future", + "noTestimony": "No testimony found for this legislator's bills.", "notClaimed": "This legislator has not claimed their MAPLE account", "otherTestimony": "Others' testimony on their bills", "party": { @@ -52,6 +53,11 @@ "party": "Party", "republican": "Republican Party" }, + "position": { + "endorse": "Endorse", + "neutral": "Neutral", + "oppose": "Oppose" + }, "stateRepresentative": "State Representative", "stateSenator": "State Senator", "submit": "Submit", @@ -66,5 +72,6 @@ }, "termsServed": "Terms Served", "upcomingHearings": "Upcoming Hearings", - "viewAllHearings": "View all hearings" + "viewAllHearings": "View all hearings", + "viewAllTestimony": "View all testimony" } \ No newline at end of file diff --git a/public/locales/en/profile.json b/public/locales/en/profile.json index fca924cbb..4630934d1 100644 --- a/public/locales/en/profile.json +++ b/public/locales/en/profile.json @@ -8,6 +8,7 @@ "followedContent": "Followed Content", "following" : "Following", "notficationFrequencyDropdown": "open envelope with letter, toggles update frequency options", + "unfollow": "Unfollow", "yourTestimonies": "Your Testimonies" }, "content": {