From 46186e95df490705f8284f123e2c5445827adc4e Mon Sep 17 00:00:00 2001 From: nyne Date: Fri, 20 Jun 2025 13:49:36 +0800 Subject: [PATCH] Add comment update functionality with UI integration --- frontend/src/network/network.ts | 16 ++++ frontend/src/pages/resource_details_page.tsx | 85 +++++++++++++++++++- server/api/comment.go | 26 ++++++ server/dao/comment.go | 13 +++ server/service/comment.go | 15 ++++ 5 files changed, 151 insertions(+), 4 deletions(-) diff --git a/frontend/src/network/network.ts b/frontend/src/network/network.ts index ccf9301..583f1d2 100644 --- a/frontend/src/network/network.ts +++ b/frontend/src/network/network.ts @@ -934,6 +934,22 @@ class Network { } } + async updateComment( + commentID: number, + content: string, + ): Promise> { + try { + const response = await axios.putForm( + `${this.apiBaseUrl}/comments/${commentID}`, + { content }, + ); + return response.data; + } catch (e: any) { + console.error(e); + return { success: false, message: e.toString() }; + } + } + async listComments( resourceID: number, page: number = 1, diff --git a/frontend/src/pages/resource_details_page.tsx b/frontend/src/pages/resource_details_page.tsx index d1785c7..ac1267f 100644 --- a/frontend/src/pages/resource_details_page.tsx +++ b/frontend/src/pages/resource_details_page.tsx @@ -1199,7 +1199,7 @@ function Comments({ resourceId }: { resourceId: number }) { ) : ( )} +
-
+ {new Date(comment.created_at).toLocaleString()} -
+
{displayContent} @@ -1308,6 +1309,11 @@ function CommentTile({ comment }: { comment: Comment }) {
)}
+ {app.user?.id === comment.user.id && ( +
+ +
+ )}
); } @@ -1380,3 +1386,74 @@ function DeleteFileDialog({ ); } + +function EditCommentDialog({ + comment, +}: { + comment: Comment; +}) { + const [isLoading, setLoading] = useState(false); + const [content, setContent] = useState(comment.content); + const { t } = useTranslation(); + const reload = useContext(context); + + const handleUpdate = async () => { + if (isLoading) { + return; + } + setLoading(true); + const res = await network.updateComment(comment.id, content); + const dialog = document.getElementById( + `edit_comment_dialog_${comment.id}`, + ) as HTMLDialogElement; + dialog.close(); + if (res.success) { + showToast({ + message: t("Comment updated successfully"), + type: "success", + }); + reload(); + } else { + showToast({ message: res.message, type: "error" }); + } + setLoading(false); + }; + + return ( + <> + + +
+

{t("Edit Comment")}

+