|
1 | | -export function Testimony() { |
2 | | - return <div>- Testimony</div> |
| 1 | +import { useMemo } from "react" |
| 2 | +import { useTranslation } from "next-i18next" |
| 3 | +import styled from "styled-components" |
| 4 | + |
| 5 | +import { useAuth } from "components/auth" |
| 6 | +import { SmartDisclaimer } from "components/bill/SmartDisclaimer" |
| 7 | +import { usePublishedTestimonyListing } from "components/db/testimony/usePublishedTestimonyListing" |
| 8 | +import { NoResults } from "components/search/NoResults" |
| 9 | +import { TestimonyItem } from "components/TestimonyCard/TestimonyItem" |
| 10 | + |
| 11 | +const DisclaimerBlock = styled.div` |
| 12 | + align-items: flex-start; |
| 13 | + background-color: #f0f4ff; |
| 14 | + border: "1px #d1d6e7 solid"; |
| 15 | + border-radius: 5px; |
| 16 | + color: #1a3185; |
| 17 | + display: flex; |
| 18 | + font-size: 13px; |
| 19 | + gap: 10px; |
| 20 | + line-height: 1.6; |
| 21 | + margin-top: 14px; |
| 22 | + margin-bottom: 14px; |
| 23 | + padding: 12px 16px; |
| 24 | +` |
| 25 | + |
| 26 | +const TestimonyBlock = styled.div` |
| 27 | + background-color: white; |
| 28 | + border: "1px #ced4da solid"; |
| 29 | + border-radius: 5px; |
| 30 | + font-size: 11px; |
| 31 | + margin-bottom: 14px; |
| 32 | + padding: 0px 16px; |
| 33 | +` |
| 34 | + |
| 35 | +function Disclaimer({ fullname }: { fullname?: string }) { |
| 36 | + const { t } = useTranslation("legislators") |
| 37 | + |
| 38 | + return ( |
| 39 | + <DisclaimerBlock> |
| 40 | + <svg |
| 41 | + width="16" |
| 42 | + height="16" |
| 43 | + viewBox="0 0 24 24" |
| 44 | + fill="none" |
| 45 | + stroke="#1a3185" |
| 46 | + stroke-width="2" |
| 47 | + // style="flex-shrink:0;margin-top:1px" |
| 48 | + > |
| 49 | + <circle cx="12" cy="12" r="10"></circle> |
| 50 | + <line x1="12" y1="8" x2="12" y2="12"></line> |
| 51 | + <line x1="12" y1="16" x2="12.01" y2="16"></line> |
| 52 | + </svg> |
| 53 | + <div> |
| 54 | + {fullname} {t("canSubmit")} |
| 55 | + </div> |
| 56 | + </DisclaimerBlock> |
| 57 | + ) |
| 58 | +} |
| 59 | + |
| 60 | +export function Testimony({ |
| 61 | + fullname, |
| 62 | + pageId |
| 63 | +}: { |
| 64 | + fullname?: string |
| 65 | + pageId?: string |
| 66 | +}) { |
| 67 | + const { t } = useTranslation("testimony") |
| 68 | + const { user } = useAuth() |
| 69 | + |
| 70 | + const testimony = usePublishedTestimonyListing({ |
| 71 | + uid: pageId |
| 72 | + }) |
| 73 | + |
| 74 | + const allTestimonies = useMemo(() => { |
| 75 | + const legislatorTestimonies = testimony.items.result ?? [] |
| 76 | + |
| 77 | + // Combine and sort by publishedAt (newest first), then take 4 most recent |
| 78 | + return [...legislatorTestimonies] |
| 79 | + .sort((a, b) => b.publishedAt.toMillis() - a.publishedAt.toMillis()) |
| 80 | + .slice(0, 4) |
| 81 | + }, [testimony.items.result]) |
| 82 | + |
| 83 | + return ( |
| 84 | + <> |
| 85 | + <Disclaimer fullname={fullname} /> |
| 86 | + {allTestimonies.length > 0 ? ( |
| 87 | + <div> |
| 88 | + {allTestimonies.map(testimony => ( |
| 89 | + <TestimonyBlock key={testimony.id}> |
| 90 | + <TestimonyItem |
| 91 | + testimony={testimony} |
| 92 | + isUser={testimony.authorUid === user?.uid} |
| 93 | + onProfilePage={true} |
| 94 | + /> |
| 95 | + </TestimonyBlock> |
| 96 | + ))} |
| 97 | + </div> |
| 98 | + ) : ( |
| 99 | + <NoResults>{t("viewTestimony.noTestimonies")}</NoResults> |
| 100 | + )} |
| 101 | + </> |
| 102 | + ) |
3 | 103 | } |
0 commit comments