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 }}
-