From 6cc8325d2be05b6cdcb304ab062529b2db6311ce Mon Sep 17 00:00:00 2001
From: isUnknown
Date: Tue, 7 Jan 2025 15:19:50 +0100
Subject: [PATCH] #88 - edit comment fonctional but not styled
---
.../site/plugins/comments/routes/update.php | 47 +++++++++++++------
src/components/comments/Comment.vue | 45 ++++++++++++++++--
src/components/comments/Comments.vue | 7 +--
src/stores/api.js | 24 ++++++++++
src/stores/dialog.js | 2 +
5 files changed, 102 insertions(+), 23 deletions(-)
diff --git a/public/site/plugins/comments/routes/update.php b/public/site/plugins/comments/routes/update.php
index 6972193..ca875d4 100644
--- a/public/site/plugins/comments/routes/update.php
+++ b/public/site/plugins/comments/routes/update.php
@@ -4,25 +4,42 @@ return [
'pattern' => '(:all)update-comment.json',
'method' => 'POST',
'action' => function () {
- $json = file_get_contents('php://input');
- $data = json_decode($json);
+ $json = file_get_contents('php://input');
+ $data = json_decode($json);
- $page = page($data->pageUri);
- $file = $page->file($data->fileName);
- $user = kirby()->user($data->userUuid);
+ $page = page($data->location->page->uri);
+ $project = page($data->location->project->uri);
+ $file = $page->file($data->location->file->uuid);
+ $isReply = $data->location->parentId ?? false;
+ $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
- $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
+ foreach ($comments as $key => &$comment) {
+ if ($isReply) {
+ if ($comment['id'] === $data->location->parentId) {
+ foreach ($comment['replies'] as $replyKey => $reply) {
+ if ($reply['id'] === $data->id) {
+ $comment['replies'][$replyKey]["text"] = $data->text;
+ $comment['replies'][$replyKey]["date"] = $data->date;
+ $comment['replies'] = array_values($comment['replies']);
+ }
+ }
+ }
+ } else {
+ if ($comment['id'] === $data->id) {
+ $comments[$key]["text"] = $data->text;
+ $comments[$key]["date"] = $data->date;
+ }
+ }
+ }
- $comments[$data->id]['text'] = $data->text;
- $comments[$data->id]['date'] = $data->date;
-
- $newFile = $file->update([
- 'comments' => $comments
- ]);
+ $comments = array_values($comments);
- $user->sendNotification('comments', $comments[$data->id]);
-
- return getFileData($newFile);
+ $newFile = $file->update([
+ 'comments' => $comments
+ ]);
+
+ echo json_encode(getFileData($newFile));
+ exit;
}
];
\ No newline at end of file
diff --git a/src/components/comments/Comment.vue b/src/components/comments/Comment.vue
index 555c075..6b83e23 100644
--- a/src/components/comments/Comment.vue
+++ b/src/components/comments/Comment.vue
@@ -20,10 +20,14 @@
>
-
+
+
{{ comment.text }}
-