Skip to content

Commit 162167f

Browse files
committed
Add missing UI update after comment added
1 parent e564057 commit 162167f

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

frontend/src/components/content/CommentList.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

frontend/src/pages/content/ContentEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from "react";
22
import { useAuth } from "../../hooks/AuthProvider/useAuth";
3-
import { useNavigate } from "react-router-dom";
3+
import { useNavigate, useParams } from "react-router-dom";
44
import Cookies from "js-cookie";
55

66
// TipTap (Import)

frontend/src/pages/content/ContentView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export default function ContentView() {
214214
if (localStorage.getItem("userUID") === content?.creatorUID) {
215215
try {
216216
// Delete content
217-
const user_id = user?.uid;
217+
const user_id = auth.user?.uid;
218218
const content_id = content?.uid;
219219
await axios({
220220
method: "delete",

0 commit comments

Comments
 (0)