From 8f2db63c9d94c62686dfaf8fbf7544a8cd3747f8 Mon Sep 17 00:00:00 2001 From: Vahn Gomes Date: Wed, 11 Oct 2023 22:21:35 -0400 Subject: [PATCH] Users can now edit comments --- backend/app.js | 2 +- .../src/components/Post/CommentComponent.vue | 61 ++++++++++++++++++- frontend/src/components/PostComponent.vue | 15 +++++ 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/backend/app.js b/backend/app.js index 17cbc0bc..6e94f691 100644 --- a/backend/app.js +++ b/backend/app.js @@ -58,7 +58,7 @@ app.use(function (req, res, next) { "Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization, X-Forwarded-For" ); - res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"); + res.header("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS"); res.header("Access-Control-Allow-Credentials", true); next(); }); diff --git a/frontend/src/components/Post/CommentComponent.vue b/frontend/src/components/Post/CommentComponent.vue index f075553f..d4d84966 100644 --- a/frontend/src/components/Post/CommentComponent.vue +++ b/frontend/src/components/Post/CommentComponent.vue @@ -10,7 +10,35 @@ />
-

{{ comment.comment }}

+

{{ comment.comment }}

+ + + + + +
Posted by {{ comment.user?.username }} @@ -52,8 +80,10 @@ class="btn btn-edit btn-sm mr-2 dropdown-item" type="button" style="color: #fff; cursor: pointer" + @click="toggleEditing" > - Edit + + {{ isEditing ? "Cancel" : "Edit" }}
@@ -332,6 +333,20 @@ export default { (comment) => comment._id !== deletedCommentId ); }, + handleCommentEdited(editedComment) { + console.log("Comment Edited: ", editedComment._id); + + // Find the comment with the specified _id + const commentIndex = this.thisPost.comments.findIndex( + (comment) => comment._id === editedComment._id + ); + + // Update the comment + this.thisPost.comments[commentIndex].comment = editedComment.comment; + + // Update the updatedAt field + this.thisPost.comments[commentIndex].updatedAt = editedComment.updatedAt; + }, }, mounted() { // Check if the post is liked