You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/01/18 07:31:09 UTC

(incubator-answer) 02/03: comments less than 3 resorting by created_at in frontend

This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit bbc3e5c91e116823ed8bd46ede824e5705b31080
Author: Yang Wong <yang wang>
AuthorDate: Wed Jan 10 12:23:32 2024 +0100

    comments less than 3 resorting by created_at in frontend
---
 internal/service/comment/comment_service.go | 6 ------
 ui/src/components/Comment/index.tsx         | 3 +++
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/internal/service/comment/comment_service.go b/internal/service/comment/comment_service.go
index 55a61996..0caa2a14 100644
--- a/internal/service/comment/comment_service.go
+++ b/internal/service/comment/comment_service.go
@@ -40,7 +40,6 @@ import (
 	"github.com/jinzhu/copier"
 	"github.com/segmentfault/pacman/errors"
 	"github.com/segmentfault/pacman/log"
-	"sort"
 	"time"
 )
 
@@ -342,11 +341,6 @@ func (cs *CommentService) GetCommentWithPage(ctx context.Context, req *schema.Ge
 	if err != nil {
 		return nil, err
 	}
-	if total <= 3 {
-		sort.SliceStable(commentList, func(i, j int) bool {
-			return commentList[i].CreatedAt.Before(commentList[j].CreatedAt)
-		})
-	}
 	resp := make([]*schema.GetCommentResp, 0)
 	for _, comment := range commentList {
 		commentResp, err := cs.convertCommentEntity2Resp(ctx, req, comment)
diff --git a/ui/src/components/Comment/index.tsx b/ui/src/components/Comment/index.tsx
index e5b2db7d..5443378d 100644
--- a/ui/src/components/Comment/index.tsx
+++ b/ui/src/components/Comment/index.tsx
@@ -98,6 +98,9 @@ const Comment = ({ objectId, mode, commentId }) => {
       setComments([...comments, ...data.list]);
     }
     const user: Types.PageUser[] = [];
+    if (data.count <= 3) {
+      data.list.sort((a, b) => a.created_at - b.created_at);
+    }
     data.list.forEach((item) => {
       user.push({
         id: item.user_id,