@@ -65,18 +65,22 @@ export default function CommentList({
6565 if ( ! user . uid ) navigate ( `../authentication/login` ) ;
6666
6767 // Add comment to the backend
68- const comment = await CommentService . publishComment (
68+ const result = await CommentService . publishComment (
6969 contentId ,
7070 newComment ,
7171 user . uid
7272 ) ;
7373
7474 // Check if the comment was added successfully
75- if ( comment instanceof Error ) {
75+ if ( result instanceof Error ) {
7676 toast ( "An error occurred while adding the comment." , "error" ) ;
7777 return ;
7878 }
7979
80+ // Update comments list to reflect the new comment
81+ setComments ( ( prevComments ) => [ ...prevComments , result . comment ] ) ;
82+ setNumComments ( ( prevNum ) => prevNum + 1 ) ;
83+
8084 setNewComment ( "" ) ;
8185 } ;
8286
@@ -93,14 +97,14 @@ export default function CommentList({
9397 }
9498
9599 // Update comment in the backend
96- const comment = await CommentService . updateComment (
100+ const result = await CommentService . updateComment (
97101 selectedCommentEdit . comment_id ,
98102 selectedCommentEdit . text ,
99103 contentId
100104 ) ;
101105
102106 // Check if the comment was updated successfully
103- if ( comment instanceof Error ) {
107+ if ( result instanceof Error ) {
104108 toast ( "An error occurred while updating the comment." , "error" ) ;
105109 return ;
106110 }
0 commit comments