notifications seems to work but new comments erase previous ones

This commit is contained in:
isUnknown 2024-10-28 15:55:14 +01:00
parent 44361e614d
commit 85537d3465
5 changed files with 16 additions and 130 deletions

View file

@ -7,20 +7,20 @@ return [
$json = file_get_contents('php://input');
$data = json_decode($json);
// return json_encode($data->pageUri);
$page = page($data->pageUri);
$file = $page->file($data->fileName);
$user = kirby()->user($data->userUuid);
$comments = $file->comments()->isEmpty() == true ? [] : Data::decode($file->comments()->toArray()['comments'], 'yaml');
$comments = $file->comments()->isEmpty() == true ? [] : [];
$newComment = [
'fileUuid' => (string )$file->uuid(),
'page' => $data->targetPage,
'text' => $data->text,
'username' => $user->name()->isNotEmpty() ? (string) $user->name() : (string) $user->email(),
'date' => (string) $data->date,
'id' => $data->id
'id' => $data->id,
];
$comments[$data->targetPage][$data->id] = $newComment;

View file

@ -1,7 +1,7 @@
<?php
return [
'pattern' => '(:all)logout.php',
'pattern' => '(:all)logout',
'action' => function () {
$kirby = kirby();
$user = $kirby->user();

View file

@ -5,15 +5,15 @@ return function ($page, $kirby) {
$data['template'] = (string) $page->template();
$userData = [
"role" => $kirby->user()->role(),
"uuid" => $kirby->user()->uuid(),
"role" => (string) $kirby->user()->role(),
"uuid" => (string) $kirby->user()->uuid(),
"notifications" => Yaml::decode($kirby->user()->notifications()->value()),
];
if ($kirby->user()->role() == 'client') {
$userData['client'] = [
"name" => $kirby->user()->client()->toPage()->title(),
"uuid" => $kirby->user()->client()->toPage()->uuid()
"name" => (string) $kirby->user()->client()->toPage()->title(),
"uuid" => (string) $kirby->user()->client()->toPage()->uuid()
];
}