|
1 | | -import { useTranslation } from "next-i18next" |
2 | 1 | import { ReactElement } from "react" |
3 | 2 | import CardBootstrap from "react-bootstrap/Card" |
4 | | -import { formatBillId } from "components/formatting" |
5 | | -import { Internal } from "components/links" |
6 | 3 |
|
7 | 4 | interface CardTitleProps { |
8 | | - authorUid?: string |
9 | | - billId?: string |
10 | | - court?: string |
11 | 5 | header?: string |
12 | 6 | subheader?: string |
13 | 7 | timestamp?: string |
14 | 8 | imgSrc?: string |
| 9 | + imgTitle?: string |
15 | 10 | inHeaderElement?: ReactElement |
16 | | - isBillMatch?: boolean |
17 | | - isUserMatch?: boolean |
18 | | - type?: string |
19 | | - userRole?: string |
20 | 11 | } |
21 | 12 |
|
22 | 13 | export const CardTitle = (props: CardTitleProps) => { |
23 | | - const { |
24 | | - authorUid, |
25 | | - billId, |
26 | | - court, |
27 | | - header, |
28 | | - isBillMatch, |
29 | | - isUserMatch, |
30 | | - subheader, |
31 | | - type, |
32 | | - userRole |
33 | | - } = props |
34 | | - |
| 14 | + const { header, subheader, timestamp, imgSrc, imgTitle, inHeaderElement } = |
| 15 | + props |
35 | 16 | return ( |
36 | | - <CardBootstrap.Body className={`align-items-center d-flex px-2 pt-2 pb-0`}> |
37 | | - <CardHeaderImg type={type} userRole={userRole} /> |
38 | | - <CardBootstrap.Body className="px-3 py-0"> |
39 | | - <CardTitleHeadline |
40 | | - authorUid={authorUid} |
41 | | - billId={billId} |
42 | | - court={court} |
43 | | - header={header} |
44 | | - subheader={subheader} |
45 | | - type={type} |
46 | | - /> |
47 | | - <CardTitleFollowing |
48 | | - billId={billId} |
49 | | - header={header} |
50 | | - subheader={subheader} |
51 | | - isBillMatch={isBillMatch} |
52 | | - isUserMatch={isUserMatch} |
53 | | - type={type} |
54 | | - /> |
55 | | - </CardBootstrap.Body> |
56 | | - </CardBootstrap.Body> |
57 | | - ) |
58 | | -} |
59 | | - |
60 | | -const CardHeaderImg = (props: CardTitleProps) => { |
61 | | - const { type, userRole } = props |
62 | | - |
63 | | - let avatar = `individualUser.svg` |
64 | | - if (userRole == `organization`) { |
65 | | - avatar = `OrganizationUser.svg` |
66 | | - } |
67 | | - |
68 | | - switch (type) { |
69 | | - case "testimony": |
70 | | - return ( |
71 | | - <div className="justify-content-middle d-flex flex-column align-items-center"> |
72 | | - <img alt="capitol building" src={avatar} width="32" height="32" /> |
73 | | - </div> |
74 | | - ) |
75 | | - case "bill": |
76 | | - return ( |
77 | | - <div className="justify-content-middle d-flex flex-column align-items-center"> |
78 | | - <img |
79 | | - alt="capitol building" |
80 | | - src={`/images/bill-capitol.svg`} |
81 | | - width="32" |
82 | | - height="32" |
83 | | - /> |
84 | | - </div> |
85 | | - ) |
86 | | - default: |
87 | | - return <></> |
88 | | - } |
89 | | -} |
90 | | - |
91 | | -const CardTitleHeadline = (props: CardTitleProps) => { |
92 | | - const { authorUid, billId, court, header, subheader, type } = props |
93 | | - const { t } = useTranslation("common") |
94 | | - |
95 | | - switch (type) { |
96 | | - case "testimony": |
97 | | - return ( |
98 | | - <> |
99 | | - {header && subheader && ( |
100 | | - <CardBootstrap.Title |
101 | | - className={`align-items-start fs-6 lh-sm mb-1 text-secondary`} |
102 | | - > |
103 | | - <Internal href={`/profile?id=${authorUid}`}> |
104 | | - <strong>{subheader}</strong> |
105 | | - </Internal> |
106 | | - |
107 | | - {t("newsfeed.endorsed")} |
108 | | - <a href={`/bills/${court}/${billId}`}> |
109 | | - {billId && <strong>{formatBillId(billId)}</strong>} |
110 | | - </a> |
111 | | - </CardBootstrap.Title> |
112 | | - )} |
113 | | - </> |
114 | | - ) |
115 | | - case "bill": |
116 | | - return ( |
117 | | - <> |
118 | | - {header && ( |
119 | | - <CardBootstrap.Title |
120 | | - className={`align-items-start fs-6 lh-sm mb-1 text-secondary`} |
121 | | - > |
122 | | - {billId && ( |
123 | | - <a href={`/bills/${court}/${billId}`}> |
124 | | - <strong>{formatBillId(billId)}</strong> |
125 | | - </a> |
126 | | - )}{" "} |
127 | | - {subheader && ( |
128 | | - <> |
129 | | - {t("newsfeed.actionUpdate")} |
130 | | - {subheader} |
131 | | - </> |
132 | | - )} |
133 | | - </CardBootstrap.Title> |
134 | | - )} |
135 | | - </> |
136 | | - ) |
137 | | - default: |
138 | | - return ( |
139 | | - <CardBootstrap.Title |
140 | | - className={`align-items-start fs-6 lh-sm mb-1 text-secondary`} |
141 | | - > |
142 | | - <strong>{header}</strong> |
143 | | - </CardBootstrap.Title> |
144 | | - ) |
145 | | - } |
146 | | -} |
147 | | - |
148 | | -const CardTitleFollowing = (props: CardTitleProps) => { |
149 | | - const { billId, header, isBillMatch, isUserMatch, subheader, type } = props |
150 | | - const { t } = useTranslation("common") |
151 | | - |
152 | | - if (type == ``) { |
153 | | - return <></> |
154 | | - } else if (type === `bill`) { |
155 | | - return ( |
156 | | - <> |
| 17 | + <CardBootstrap.Body |
| 18 | + className={`align-items-center bg-secondary d-flex text-white`} |
| 19 | + > |
| 20 | + <div className="justify-content-middle d-flex flex-column align-items-center"> |
| 21 | + {imgSrc && <img alt="" src={imgSrc} width="75" height="75" />} |
| 22 | + <div className="mt-1">{imgTitle}</div> |
| 23 | + </div> |
| 24 | + <CardBootstrap.Body> |
157 | 25 | {header && ( |
158 | | - <CardBootstrap.Title |
159 | | - className={`align-items-start fs-6 lh-sm mb-1 text-body-tertiary`} |
160 | | - > |
161 | | - {isBillMatch ? ( |
162 | | - <>{t("newsfeed.follow")}</> |
163 | | - ) : ( |
164 | | - <>{t("newsfeed.notFollow")}</> |
165 | | - )} |
166 | | - {billId && <strong>{formatBillId(billId)}</strong>} |
| 26 | + <CardBootstrap.Title className={`fs-4 lh-sm mb-1`}> |
| 27 | + {header} |
167 | 28 | </CardBootstrap.Title> |
168 | 29 | )} |
169 | | - </> |
170 | | - ) |
171 | | - } else if (isBillMatch && isUserMatch) { |
172 | | - return ( |
173 | | - <CardBootstrap.Title |
174 | | - className={`align-items-start fs-6 lh-sm mb-1 text-body-tertiary`} |
175 | | - > |
176 | | - {t("newsfeed.follow")} |
177 | | - {billId && <strong>{formatBillId(billId)}</strong>} |
178 | | - {t("newsfeed.and")} |
179 | | - {subheader} |
180 | | - </CardBootstrap.Title> |
181 | | - ) |
182 | | - } else if (isBillMatch === true && isUserMatch === false) { |
183 | | - return ( |
184 | | - <CardBootstrap.Title |
185 | | - className={`align-items-start fs-6 lh-sm mb-1 text-body-tertiary`} |
186 | | - > |
187 | | - {t("newsfeed.follow")} |
188 | | - {billId && <strong>{formatBillId(billId)}</strong>} |
189 | | - </CardBootstrap.Title> |
190 | | - ) |
191 | | - } else if (isBillMatch === false && isUserMatch === true) { |
192 | | - return ( |
193 | | - <CardBootstrap.Title |
194 | | - className={`align-items-start fs-6 lh-sm mb-1 text-body-tertiary`} |
195 | | - > |
196 | | - {t("newsfeed.follow")} |
197 | | - {subheader} |
198 | | - </CardBootstrap.Title> |
199 | | - ) |
200 | | - } else { |
201 | | - return ( |
202 | | - <CardBootstrap.Title |
203 | | - className={`align-items-start fs-6 lh-sm mb-1 text-body-tertiary`} |
204 | | - > |
205 | | - {t("newsfeed.notFollowEither")} |
206 | | - {billId && <strong>{formatBillId(billId)}</strong>} |
207 | | - {t("newsfeed.or")} |
208 | | - {subheader} |
209 | | - </CardBootstrap.Title> |
210 | | - ) |
211 | | - } |
| 30 | + {subheader && ( |
| 31 | + <CardBootstrap.Text className={`fs-5 lh-sm mb-1`}> |
| 32 | + {subheader} |
| 33 | + </CardBootstrap.Text> |
| 34 | + )} |
| 35 | + {timestamp && ( |
| 36 | + <CardBootstrap.Text className={`fs-6 lh-sm`}> |
| 37 | + {timestamp} |
| 38 | + </CardBootstrap.Text> |
| 39 | + )} |
| 40 | + </CardBootstrap.Body> |
| 41 | + {inHeaderElement && inHeaderElement} |
| 42 | + </CardBootstrap.Body> |
| 43 | + ) |
212 | 44 | } |
0 commit comments