You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by "insistedMarin (via GitHub)" <gi...@apache.org> on 2024/01/09 18:22:35 UTC

[PR] Fix/1.2.5/unexpanded comments [incubator-answer]

insistedMarin opened a new pull request, #717:
URL: https://github.com/apache/incubator-answer/pull/717

   **Title**: Improved Comment Sorting and Display Logic
   
   **Description**:
   
   This pull request introduces optimized sorting and display logic for comments. The focus is on enhancing user interaction with the comments section, particularly when dealing with varying numbers of comments.
   
   **Key Updates**:
   
   Top Comments Priority:
   
   The top 3 highest-voted comments are displayed first, sorted by vote count and then by oldest posting time in case of a tie.
   Handling Fewer Comments:
   
   For scenarios with 3 or fewer comments, comments are sorted by posting time from oldest to newest after the database query. This approach was chosen due to the smaller data volume, enabling efficient post-query sorting.
   Expandable Comments:
   
   Added an "Expand Comments" feature. Post-expansion, comments are sorted by posting time from oldest to newest and loaded 15 at a time.
   Dynamic Comment Count:
   
   The expansion button shows the number of remaining comments to be viewed.
   **Conclusion**:
   
   These improvements aim to make the comment section more interactive and user-friendly, providing clarity and ease of access to the most relevant comments


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/1.2.5/unexpanded comments [incubator-answer]

Posted by "shuashuai (via GitHub)" <gi...@apache.org>.
shuashuai commented on code in PR #717:
URL: https://github.com/apache/incubator-answer/pull/717#discussion_r1453010160


##########
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) {

Review Comment:
   Should be sorted first and then assigned.
   
   ```
   if (data.count <= 3) {
         data.list.sort((a, b) => a.created_at - b.created_at);
       }
     if (pageIndex === 1 || pageIndex === 0) {
         setComments(data?.list);
       } else {
         setComments([...comments, ...data.list]);
       }
       
       ... 
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/1.2.5/unexpanded comments [incubator-answer]

Posted by "shuashuai (via GitHub)" <gi...@apache.org>.
shuashuai commented on code in PR #717:
URL: https://github.com/apache/incubator-answer/pull/717#discussion_r1454417794


##########
ui/src/components/Comment/index.tsx:
##########
@@ -92,6 +92,9 @@ const Comment = ({ objectId, mode, commentId }) => {
     if (!data) {
       return;
     }
+    if (data.count <= 3) {
+      data.list.sort((a, b) => a.created_at - b.created_at);
+    }
     if (pageIndex === 1 || pageIndex === 0) {

Review Comment:
   Sorry, I missed some conditions yesterday.  `data.count` should be the total number of comments. Here you only need to sort the data loaded for the first time and with the same number of votes by time, so `data.list.length` and `vote_Count` should be used for judgment, and it should only be processed during the first load. So it should be like this
   
   ```javascript
     if (pageIndex === 1 || pageIndex === 0) {
         if (data.list.length <= 3) {
           data.list.sort((a, b) => {
             if (a.vote_count === b.vote_count) {
               return a.created_at - b.created_at;
             }
             return 1;
           });
         }
         setComments(data?.list);
       } else {
         setComments([...comments, ...data.list]);
       }
   ```
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/1.2.5/unexpanded comments [incubator-answer]

Posted by "shuashuai (via GitHub)" <gi...@apache.org>.
shuashuai commented on code in PR #717:
URL: https://github.com/apache/incubator-answer/pull/717#discussion_r1457022193


##########
ui/src/components/Comment/index.tsx:
##########
@@ -92,6 +92,9 @@ const Comment = ({ objectId, mode, commentId }) => {
     if (!data) {
       return;
     }
+    if (data.count <= 3) {
+      data.list.sort((a, b) => a.created_at - b.created_at);
+    }
     if (pageIndex === 1 || pageIndex === 0) {

Review Comment:
   >  the main condition is to determine whether the total number of comments is greater than 3.
   
   Your understanding is right.
   
   >  In addition, the default sorting for "page 0" is votes from high to low and then time from old to new. So no need to reorder.
   
   To be exact, the default sorting should not be based on "page 0", but you sort based on whether the total number is greater than 3, because "page 0" is a condition used by the front end to distinguish whether to load more,when using the useQueryComments` method, the parameter passed is page = 0, and the actual call passed is page=1.
   
   The code is correct now!
   
   Finally, thank you very much for your carefulness and contribution!
   
   
   
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/1.2.5/unexpanded comments [incubator-answer]

Posted by "LinkinStars (via GitHub)" <gi...@apache.org>.
LinkinStars commented on code in PR #717:
URL: https://github.com/apache/incubator-answer/pull/717#discussion_r1446872537


##########
internal/service/comment/comment_service.go:
##########
@@ -342,6 +342,11 @@ 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)
+		})
+	}

Review Comment:
   From the point of view of API design, this sorting can't be executed in the backend, it should be executed by the frontend. 
   The reason is that when the client passes a request for sorting by vote to this API, the sorting rules will change when the number is less than three, and the caller will think that the API is not designed properly, and that it is not sorted according to my requirements. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/1.2.5/unexpanded comments [incubator-answer]

Posted by "insistedMarin (via GitHub)" <gi...@apache.org>.
insistedMarin commented on code in PR #717:
URL: https://github.com/apache/incubator-answer/pull/717#discussion_r1447253231


##########
internal/service/comment/comment_service.go:
##########
@@ -342,6 +342,11 @@ 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)
+		})
+	}

Review Comment:
   Thank you very much for your guidance, I have solved the sorting problem on the front end.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/1.2.5/unexpanded comments [incubator-answer]

Posted by "shuashuai (via GitHub)" <gi...@apache.org>.
shuashuai commented on code in PR #717:
URL: https://github.com/apache/incubator-answer/pull/717#discussion_r1453010160


##########
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) {

Review Comment:
   Should be sorted first and then assigned.
   
   ```
   
     if (pageIndex === 1 || pageIndex === 0) {
     
      if (data.count <= 3) {
         data.list.sort((a, b) => a.created_at - b.created_at);
       }
         setComments(data?.list);
       } else {
         setComments([...comments, ...data.list]);
       }
       
       ... 
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/1.2.5/unexpanded comments [incubator-answer]

Posted by "insistedMarin (via GitHub)" <gi...@apache.org>.
insistedMarin commented on code in PR #717:
URL: https://github.com/apache/incubator-answer/pull/717#discussion_r1453282460


##########
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) {

Review Comment:
   Thank you very much, I have corrected the code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/1.2.5/unexpanded comments [incubator-answer]

Posted by "insistedMarin (via GitHub)" <gi...@apache.org>.
insistedMarin commented on code in PR #717:
URL: https://github.com/apache/incubator-answer/pull/717#discussion_r1455582817


##########
ui/src/components/Comment/index.tsx:
##########
@@ -92,6 +92,9 @@ const Comment = ({ objectId, mode, commentId }) => {
     if (!data) {
       return;
     }
+    if (data.count <= 3) {
+      data.list.sort((a, b) => a.created_at - b.created_at);
+    }
     if (pageIndex === 1 || pageIndex === 0) {

Review Comment:
   ![image](https://github.com/apache/incubator-answer/assets/50784434/f461d4d4-07f1-4c20-9803-5ff2bc3bdbe0)
   Okay, there might be some confusion in the needs. I want to clarify the needs with you.
   
   In my opinion, the main condition is to determine whether the total number of comments is greater than 3, and the comments less than or equal to 3 are displayed in order of time from old to new. For comments larger than 3, they will be displayed in two sortings initially and after expansion.
   
   If the main condition is the number of comments obtained, then sorting from old to new should only be effective for cases less than 3. But the number of votes for this case is not a sorting condition.
   
   In addition, the default sorting for "page 0" is votes from high to low and then time from old to new. So no need to reorder.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/1.2.5/unexpanded comments [incubator-answer]

Posted by "LinkinStars (via GitHub)" <gi...@apache.org>.
LinkinStars merged PR #717:
URL: https://github.com/apache/incubator-answer/pull/717


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org