Skip to content

Commit cc2b46a

Browse files
committed
fix: truncated post description
1 parent dbb0f2a commit cc2b46a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

client/src/components/PostCard.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ import { convertToBase64, getThumbnail } from '@/lib/utils'
4242
import { useUser } from '@clerk/clerk-react'
4343
import { useDeletePost, useUpdatePost } from '@/hooks'
4444

45+
const truncate = (text, wordLimit) => {
46+
const words = text.split(' ')
47+
return words.length > wordLimit
48+
? `${words.slice(0, wordLimit).join(' ')} ...`
49+
: text
50+
}
51+
4552
const MoreButton = ({ setEditing, post }) => {
4653
const [anchorEl, setAnchorEl] = useState(null)
4754
const open = Boolean(anchorEl)
@@ -436,7 +443,7 @@ const StaticCard = ({ post, setEditing }) => {
436443
textOverflow="ellipsis"
437444
sx={{ WebkitLineClamp: 3, WebkitBoxOrient: 'vertical' }}
438445
>
439-
{post.description}
446+
{truncate(post.description, 20)}
440447
</Typography>
441448
</CardContent>
442449
</CardActionArea>

0 commit comments

Comments
 (0)