#88 - edit comment fonctional but not styled
This commit is contained in:
parent
ea2817244b
commit
6cc8325d2b
5 changed files with 102 additions and 23 deletions
|
|
@ -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;
|
||||
}
|
||||
];
|
||||
Loading…
Add table
Add a link
Reference in a new issue