|
| 1 | +import { doc, getDoc } from "firebase/firestore" |
| 2 | +import { Trans, useTranslation } from "next-i18next" |
| 3 | +import { useCallback, useEffect, useRef, useState } from "react" |
| 4 | +import styled from "styled-components" |
| 5 | +import { Col, Container, Image, Row } from "../bootstrap" |
| 6 | +import { HearingSidebar } from "./HearingSidebar" |
| 7 | +import { Transcriptions } from "./Transcriptions" |
| 8 | +import { firestore } from "components/firebase" |
| 9 | +import * as links from "components/links" |
| 10 | + |
| 11 | +export const CommitteeButton = styled.button` |
| 12 | + border-radius: 12px; |
| 13 | + font-size: 12px; |
| 14 | +` |
| 15 | + |
| 16 | +const LegalContainer = styled(Container)` |
| 17 | + background-color: white; |
| 18 | +` |
| 19 | + |
| 20 | +const VideoChild = styled.video` |
| 21 | + position: absolute; |
| 22 | + top: 0; |
| 23 | + left: 0; |
| 24 | + width: 100%; |
| 25 | + height: 100%; |
| 26 | + border: none; |
| 27 | +` |
| 28 | + |
| 29 | +const VideoParent = styled.div` |
| 30 | + position: relative; |
| 31 | + width: 100%; |
| 32 | + padding-top: 56.25%; /* For 16:9 aspect ratio */ |
| 33 | + overflow: hidden; |
| 34 | +` |
| 35 | + |
| 36 | +export const HearingDetails = ({ |
| 37 | + hearingId |
| 38 | +}: { |
| 39 | + hearingId: string | string[] | undefined |
| 40 | +}) => { |
| 41 | + const { t } = useTranslation(["common", "hearing"]) |
| 42 | + |
| 43 | + const videoRef = useRef<HTMLVideoElement>(null) |
| 44 | + function setCurTimeVideo(value: number) { |
| 45 | + videoRef.current ? (videoRef.current.currentTime = value) : null |
| 46 | + } |
| 47 | + |
| 48 | + const eventId = `hearing-${hearingId}` |
| 49 | + |
| 50 | + const [committeeCode, setCommitteeCode] = useState("") |
| 51 | + const [committeeName, setCommitteeName] = useState("") |
| 52 | + const [description, setDescription] = useState("") |
| 53 | + const [generalCourtNumber, setGeneralCourtNumber] = useState("") |
| 54 | + const [hearingDate, setHearingDate] = useState("") |
| 55 | + const [videoTranscriptionId, setVideoTranscriptionId] = useState("") |
| 56 | + const [videoURL, setVideoURL] = useState("") |
| 57 | + |
| 58 | + const hearingData = useCallback(async () => { |
| 59 | + const hearing = await getDoc(doc(firestore, `events/${eventId}`)) |
| 60 | + const docData = hearing.data() |
| 61 | + |
| 62 | + setCommitteeCode(docData?.content.HearingHost.CommitteeCode) |
| 63 | + setCommitteeName(docData?.content.Name) |
| 64 | + setDescription(docData?.content.Description) |
| 65 | + setGeneralCourtNumber(docData?.content.HearingHost.GeneralCourtNumber) |
| 66 | + setHearingDate(docData?.content.EventDate) |
| 67 | + setVideoTranscriptionId(docData?.videoTranscriptionId) |
| 68 | + setVideoURL(docData?.videoURL) |
| 69 | + }, [eventId]) |
| 70 | + |
| 71 | + useEffect(() => { |
| 72 | + hearingData() |
| 73 | + }, [hearingData]) |
| 74 | + |
| 75 | + return ( |
| 76 | + <Container className="mt-3 mb-3"> |
| 77 | + <h1> |
| 78 | + {t("hearing")} {hearingId} |
| 79 | + </h1> |
| 80 | + |
| 81 | + <h5 className={`mb-3`}>{description}</h5> |
| 82 | + |
| 83 | + {committeeName ? ( |
| 84 | + <links.External |
| 85 | + href={`https://malegislature.gov/Committees/Detail/${committeeCode}/${generalCourtNumber}`} |
| 86 | + > |
| 87 | + <CommitteeButton |
| 88 | + className={`btn btn-secondary d-flex text-nowrap mt-1 mx-1 p-1`} |
| 89 | + > |
| 90 | + {committeeName} |
| 91 | + </CommitteeButton> |
| 92 | + </links.External> |
| 93 | + ) : ( |
| 94 | + <></> |
| 95 | + )} |
| 96 | + |
| 97 | + <div className={`row mt-4`}> |
| 98 | + <Col className={`col-md-8`}> |
| 99 | + <LegalContainer className={`pb-2 rounded`}> |
| 100 | + <Row |
| 101 | + className={`d-flex align-items-center justify-content-between`} |
| 102 | + fontSize={"12px"} |
| 103 | + xs="auto" |
| 104 | + > |
| 105 | + <Col> |
| 106 | + <div className={`fs-6 fw-bold mt-2`}> |
| 107 | + <Image |
| 108 | + src="/images/smart-summary.svg" |
| 109 | + alt={t("bill.smart_tag")} |
| 110 | + height={`34`} |
| 111 | + width={`24`} |
| 112 | + className={`me-2 pb-1`} |
| 113 | + /> |
| 114 | + {t("bill.smart_disclaimer2")} |
| 115 | + </div> |
| 116 | + </Col> |
| 117 | + |
| 118 | + <Col> |
| 119 | + <Trans |
| 120 | + t={t} |
| 121 | + i18nKey="bill.smart_disclaimer3" |
| 122 | + components={[ |
| 123 | + // eslint-disable-next-line react/jsx-key |
| 124 | + <links.Internal href="/about/how-maple-uses-ai" /> |
| 125 | + ]} |
| 126 | + /> |
| 127 | + </Col> |
| 128 | + </Row> |
| 129 | + </LegalContainer> |
| 130 | + |
| 131 | + {videoURL ? ( |
| 132 | + <VideoParent className={`my-3`}> |
| 133 | + <VideoChild ref={videoRef} src={videoURL} controls muted /> |
| 134 | + </VideoParent> |
| 135 | + ) : ( |
| 136 | + <LegalContainer className={`fs-6 fw-bold my-3 py-2 rounded`}> |
| 137 | + {t("no_video_on_file")} |
| 138 | + </LegalContainer> |
| 139 | + )} |
| 140 | + |
| 141 | + <Transcriptions |
| 142 | + setCurTimeVideo={setCurTimeVideo} |
| 143 | + videoTranscriptionId={videoTranscriptionId} |
| 144 | + /> |
| 145 | + </Col> |
| 146 | + |
| 147 | + <div className={`col-md-4`}> |
| 148 | + <HearingSidebar |
| 149 | + committeeCode={committeeCode} |
| 150 | + generalCourtNumber={generalCourtNumber} |
| 151 | + hearingDate={hearingDate} |
| 152 | + /> |
| 153 | + </div> |
| 154 | + </div> |
| 155 | + </Container> |
| 156 | + ) |
| 157 | +} |
0 commit comments