Skip to content
2 changes: 2 additions & 0 deletions src/app/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ export const SCROLL_TO_TOP_SHOW = 500;
export const TAG_MAX_LENGTH = 15;

export const MAX_NUMBER_OF_TAGS = 5;

export const MAX_LAST_COMMENT_LENGTH = 140;
12 changes: 12 additions & 0 deletions src/common/utils/truncateLongText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { MAX_LAST_COMMENT_LENGTH } from 'app/constants';

export const truncateLongText = (value) => {
let str = value;
if (str.length > MAX_LAST_COMMENT_LENGTH) {
str = str.slice(0, MAX_LAST_COMMENT_LENGTH);
const lastSpaceIndex = str.lastIndexOf(' ');
str = str.slice(0, lastSpaceIndex > -1 ? lastSpaceIndex : MAX_LAST_COMMENT_LENGTH);
str += '...';
}
return str;
};
6 changes: 5 additions & 1 deletion src/features/comments/CommentView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { selectProfile } from 'features/profile/profileSlice';
import FavoritePopoverContent from 'components/FavoritePopoverContent';
import { Popover } from 'antd';
import { truncateLongText } from 'common/utils/truncateLongText';
import { CommentsActions } from './comment-actions/CommentsActions';
import { likeCommentById, unlikeCommentById } from './commentsSlice';

Expand Down Expand Up @@ -121,7 +122,10 @@ export const CommentView = ({ comment, lastComment }) => {
<span>{comment.author?.name}</span>
<StyledTime>{dayjs(comment.createdAt).fromNow()}</StyledTime>
</div>
<Viewer theme="iqa" initialValue={comment.text} />
<Viewer
theme="iqa"
initialValue={lastComment ? truncateLongText(comment.text) : comment.text}
/>
{!lastComment && (
<StyledCommentActions>
<CommentsActions commentId={comment._id} />
Expand Down