-
-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added truncation logic for text type message in rooms #2110
base: dev
Are you sure you want to change the base?
Added truncation logic for text type message in rooms #2110
Conversation
@ajbura Hey can you review this please |
const { shouldTruncate, finalContent, finalCustomContent } = useMemo(() => { | ||
const contentStr = trimmedBody || ''; | ||
const customContentStr = typeof customBody === 'string' ? trimReplyFromBody(customBody) : ''; | ||
const needTruncate = contentStr.length > 750 || customContentStr.length > 750; | ||
return { | ||
contentStr, | ||
customContentStr, | ||
shouldTruncate: needTruncate, | ||
finalContent: isExpanded ? contentStr : truncateText(contentStr, CHARACTER_LIMIT), | ||
finalCustomContent: isExpanded | ||
? customContentStr | ||
: truncateText(customContentStr, CHARACTER_LIMIT), | ||
}; | ||
}, [trimmedBody, customBody, isExpanded]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have following concern:
- using the memoization is not really needed here as we are not doing any time consuming computation and conditional logic can be used directly while rendering.
contentStr
andcustomContentStr
are just the copy ofbody
andcustomBody
without any changes.trimReplyFromBody
is used oncustomBody
and it is only meant to be used on plainbody
.truncateText
cut the customHTML body right after 750 chars which can breaks the customHTML tags entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done . Now truncation of customHTML tags is done correctly.
{shouldTruncate && ( | ||
<button | ||
aria-expanded={isExpanded} | ||
className="show-more" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the components from design system(Folds) and CSS-in-JS instead of global css.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -27,6 +27,9 @@ import { FALLBACK_MIMETYPE, getBlobSafeMimeType } from '../../utils/mimeTypes'; | |||
import { parseGeoUri, scaleYDimension } from '../../utils/common'; | |||
import { Attachment, AttachmentBox, AttachmentContent, AttachmentHeader } from './attachment'; | |||
import { FileHeader } from './FileHeader'; | |||
import { Button } from 'folds'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pardon me for this silly mistake.
Description
Added truncation logic for chat room text messages. Previously, if anyone sent a large message, it would occupy the entire screen.
Fixes #2094
Before:
Screen.Recording.2024-12-23.at.11.23.54.AM.1.mov
After:
Screen.Recording.2024-12-23.at.11.22.02.AM.mov
Type of change
Checklist: