Skip to content

Commit cbca688

Browse files
committed
feat(truncate): Truncate text on the Newsfeed card to 600 characters
1 parent e84b1d7 commit cbca688

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

components/NewsfeedCard/NewsfeedCardBody.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import CardBootstrap from "react-bootstrap/Card"
33
import { useMediaQuery } from "usehooks-ts"
44
import { Col, Row } from "../bootstrap"
55
import { Internal } from "components/links"
6+
import { truncateText } from "components/formatting"
67

78
interface NewsfeedCardBodyProps {
89
billText?: string
@@ -33,7 +34,7 @@ export const NewsfeedBillCardBody = (props: NewsfeedCardBodyProps) => {
3334
className={`m-3`}
3435
/>
3536
<CardBootstrap.Text className={`mb-0 mt-2`}>
36-
<strong>{text}</strong>
37+
<strong>{truncateText(text, 600)}</strong>
3738
</CardBootstrap.Text>
3839
<>
3940
{t("newsfeed.actionTaken")}
@@ -52,7 +53,7 @@ export const NewsfeedBillCardBody = (props: NewsfeedCardBodyProps) => {
5253
/>
5354
<Col className={`m-2`}>
5455
<CardBootstrap.Text className={`mb-0`}>
55-
<strong>{text}</strong>
56+
<strong>{truncateText(text, 600)}</strong>
5657
</CardBootstrap.Text>
5758
<>
5859
{t("newsfeed.actionTaken")}
@@ -112,7 +113,10 @@ export const NewsfeedTestimonyCardBody = (props: NewsfeedCardBodyProps) => {
112113
</>
113114
)}
114115
</div>
115-
<strong className={`mb-4`}>{`"${text}"`}</strong>
116+
<strong className={`mb-4`}>{`"${truncateText(
117+
text,
118+
600
119+
)}"`}</strong>
116120
</Col>
117121
) : (
118122
<>
@@ -138,7 +142,10 @@ export const NewsfeedTestimonyCardBody = (props: NewsfeedCardBodyProps) => {
138142
<Col
139143
className={`d-flex align-self-center justify-content-center`}
140144
>
141-
<strong className={`m-4`}>{`"${text}"`}</strong>
145+
<strong className={`m-4`}>{`"${truncateText(
146+
text,
147+
600
148+
)}"`}</strong>
142149
</Col>
143150
</>
144151
)}

components/formatting.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,6 @@ export const decodeHtmlCharCodes = (s: string) =>
6565
s.replace(/(&#(\d+);)/g, (match, capture, charCode) =>
6666
String.fromCharCode(charCode)
6767
)
68+
69+
export const truncateText = (s: string | undefined, maxLength: number) =>
70+
!!s && s.length > maxLength ? s.substring(0, maxLength) + "..." : s

0 commit comments

Comments
 (0)