From 55a7b357725d044d613185e7a559707c39d84888 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Feb 2023 16:44:35 +0300 Subject: [PATCH 1/5] =?UTF-8?q?=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD=D0=B8=D0=B9=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B4=20=D0=BF=D0=BE=D1=81=D1=82=D0=BE=D0=BC=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B8=D1=82=D1=81=D1=8F=20=D1=81?= =?UTF-8?q?=20=D0=BE=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=87=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=BE=D0=B9=20=D0=B4=D0=BB=D0=B8=D0=BD=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/constants.js | 2 ++ src/features/comments/CommentView.jsx | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/constants.js b/src/app/constants.js index 0c2b33c..b81b3b0 100644 --- a/src/app/constants.js +++ b/src/app/constants.js @@ -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; diff --git a/src/features/comments/CommentView.jsx b/src/features/comments/CommentView.jsx index b8a86f2..eca8102 100644 --- a/src/features/comments/CommentView.jsx +++ b/src/features/comments/CommentView.jsx @@ -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 { MAX_LAST_COMMENT_LENGTH } from 'app/constants'; import { CommentsActions } from './comment-actions/CommentsActions'; import { likeCommentById, unlikeCommentById } from './commentsSlice'; @@ -121,7 +122,10 @@ export const CommentView = ({ comment, lastComment }) => { {comment.author?.name} {dayjs(comment.createdAt).fromNow()} - + {!lastComment && ( From 9a21f1135cddf63d77457f605897257a9bd787c9 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Feb 2023 17:04:39 +0300 Subject: [PATCH 2/5] =?UTF-8?q?=D0=92=D1=8B=D0=BD=D0=B5=D1=81=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=B4=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=B4=D0=BB=D0=B8=D0=BD=D0=BD=D1=8B=20=D1=82=D0=B5=D0=BA?= =?UTF-8?q?=D1=81=D1=82=D0=B0=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=83=D1=8E=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D1=8E=20=D0=B8=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D1=8F=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BA=D1=80=D0=B0=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/utils/cutLongText.js | 11 +++++++++++ src/features/comments/CommentView.jsx | 7 ++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 src/common/utils/cutLongText.js diff --git a/src/common/utils/cutLongText.js b/src/common/utils/cutLongText.js new file mode 100644 index 0000000..1c6e8a6 --- /dev/null +++ b/src/common/utils/cutLongText.js @@ -0,0 +1,11 @@ +import { MAX_LAST_COMMENT_LENGTH } from 'app/constants'; + +export const changeLastCommentLength = (value) => { + let str = value; + if (str.length > 140) { + str = str.slice(0, MAX_LAST_COMMENT_LENGTH); + str = str.substr(0, Math.min(str.length, str.lastIndexOf(' '))); + str += '...'; + } + return str; +}; diff --git a/src/features/comments/CommentView.jsx b/src/features/comments/CommentView.jsx index eca8102..580d412 100644 --- a/src/features/comments/CommentView.jsx +++ b/src/features/comments/CommentView.jsx @@ -9,7 +9,7 @@ import { useDispatch, useSelector } from 'react-redux'; import { selectProfile } from 'features/profile/profileSlice'; import FavoritePopoverContent from 'components/FavoritePopoverContent'; import { Popover } from 'antd'; -import { MAX_LAST_COMMENT_LENGTH } from 'app/constants'; +import { changeLastCommentLength } from 'common/utils/cutLongText'; import { CommentsActions } from './comment-actions/CommentsActions'; import { likeCommentById, unlikeCommentById } from './commentsSlice'; @@ -122,10 +122,7 @@ export const CommentView = ({ comment, lastComment }) => { {comment.author?.name} {dayjs(comment.createdAt).fromNow()} - + {!lastComment && ( From 0b9834a778ddc63ddb37d7e512645e88279f1ca3 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Feb 2023 17:23:42 +0300 Subject: [PATCH 3/5] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D0=BB=20?= =?UTF-8?q?=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD?= =?UTF-8?q?=D0=B3=20=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/utils/cutLongText.js | 11 ----------- src/common/utils/truncateLongText.js | 13 +++++++++++++ src/features/comments/CommentView.jsx | 4 ++-- 3 files changed, 15 insertions(+), 13 deletions(-) delete mode 100644 src/common/utils/cutLongText.js create mode 100644 src/common/utils/truncateLongText.js diff --git a/src/common/utils/cutLongText.js b/src/common/utils/cutLongText.js deleted file mode 100644 index 1c6e8a6..0000000 --- a/src/common/utils/cutLongText.js +++ /dev/null @@ -1,11 +0,0 @@ -import { MAX_LAST_COMMENT_LENGTH } from 'app/constants'; - -export const changeLastCommentLength = (value) => { - let str = value; - if (str.length > 140) { - str = str.slice(0, MAX_LAST_COMMENT_LENGTH); - str = str.substr(0, Math.min(str.length, str.lastIndexOf(' '))); - str += '...'; - } - return str; -}; diff --git a/src/common/utils/truncateLongText.js b/src/common/utils/truncateLongText.js new file mode 100644 index 0000000..d534fba --- /dev/null +++ b/src/common/utils/truncateLongText.js @@ -0,0 +1,13 @@ +import { MAX_LAST_COMMENT_LENGTH } from 'app/constants'; + +export const truncateLongText = (value) => { + let str = value; + const maxLength = MAX_LAST_COMMENT_LENGTH; + if (str.length > maxLength) { + str = str.slice(0, maxLength); + const lastSpaceIndex = str.lastIndexOf(' '); + str = str.slice(0, lastSpaceIndex > -1 ? lastSpaceIndex : maxLength); + str += '...'; + } + return str; +}; diff --git a/src/features/comments/CommentView.jsx b/src/features/comments/CommentView.jsx index 580d412..1176e78 100644 --- a/src/features/comments/CommentView.jsx +++ b/src/features/comments/CommentView.jsx @@ -9,7 +9,7 @@ import { useDispatch, useSelector } from 'react-redux'; import { selectProfile } from 'features/profile/profileSlice'; import FavoritePopoverContent from 'components/FavoritePopoverContent'; import { Popover } from 'antd'; -import { changeLastCommentLength } from 'common/utils/cutLongText'; +import { truncateLongText } from 'common/utils/truncateLongText'; import { CommentsActions } from './comment-actions/CommentsActions'; import { likeCommentById, unlikeCommentById } from './commentsSlice'; @@ -122,7 +122,7 @@ export const CommentView = ({ comment, lastComment }) => { {comment.author?.name} {dayjs(comment.createdAt).fromNow()} - + {!lastComment && ( From aef0bf54e753f809c1dcf89cdf0434fdad109e34 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Feb 2023 18:54:21 +0300 Subject: [PATCH 4/5] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20truncateLongTex?= =?UTF-8?q?t=20=D0=B8=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D0=B5=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D1=83=20=D0=BF=D0=BE?= =?UTF-8?q?=D1=81=D0=BB=D0=B5=D0=B4=D0=BD=D0=B5=D0=B3=D0=BE=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/utils/truncateLongText.js | 7 +++---- src/features/comments/CommentView.jsx | 6 +++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/common/utils/truncateLongText.js b/src/common/utils/truncateLongText.js index d534fba..6355ef6 100644 --- a/src/common/utils/truncateLongText.js +++ b/src/common/utils/truncateLongText.js @@ -2,11 +2,10 @@ import { MAX_LAST_COMMENT_LENGTH } from 'app/constants'; export const truncateLongText = (value) => { let str = value; - const maxLength = MAX_LAST_COMMENT_LENGTH; - if (str.length > maxLength) { - str = str.slice(0, maxLength); + 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 : maxLength); + str = str.slice(0, lastSpaceIndex > -1 ? lastSpaceIndex : MAX_LAST_COMMENT_LENGTH); str += '...'; } return str; diff --git a/src/features/comments/CommentView.jsx b/src/features/comments/CommentView.jsx index 1176e78..736f930 100644 --- a/src/features/comments/CommentView.jsx +++ b/src/features/comments/CommentView.jsx @@ -122,7 +122,11 @@ export const CommentView = ({ comment, lastComment }) => { {comment.author?.name} {dayjs(comment.createdAt).fromNow()} - + {lastComment ? ( + + ) : ( + + )} {!lastComment && ( From 075acfdca2a3109c9ff8c86f72b43263bbb40d69 Mon Sep 17 00:00:00 2001 From: Kuduzow Akhmad Date: Thu, 23 Feb 2023 19:30:34 +0300 Subject: [PATCH 5/5] Update src/features/comments/CommentView.jsx --- src/features/comments/CommentView.jsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/features/comments/CommentView.jsx b/src/features/comments/CommentView.jsx index 736f930..772fc82 100644 --- a/src/features/comments/CommentView.jsx +++ b/src/features/comments/CommentView.jsx @@ -122,11 +122,10 @@ export const CommentView = ({ comment, lastComment }) => { {comment.author?.name} {dayjs(comment.createdAt).fromNow()} - {lastComment ? ( - - ) : ( - - )} + {!lastComment && (