#68 - reply working + remove marker on comment delete

This commit is contained in:
isUnknown 2024-12-18 18:22:41 +01:00
parent cf83edc1e6
commit 231bb21a4f
9 changed files with 64 additions and 95 deletions

View file

@ -1,61 +1,4 @@
Comments:
-
location:
page:
uri: >
projects/miss-dior-blooming-bouquet/proposal
title: Offre commerciale
project:
title: Miss Dior Blooming Bouquet
uri: projects/miss-dior-blooming-bouquet
dialogUri: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0'
file:
uuid: file://3vTh1tMFeFM2JxaN
url: >
http://localhost:8888/media/pages/projects/miss-dior-blooming-bouquet/proposal/788ddebfe3-1731941917/des-textos-revelent-comment-bfm-sest-mise-au-service-de-sarkozy-le-boss.pdf
text: test
author:
name: Adrien Payet
email: adrien.payet@outlook.com
uuid: user://WWjXgPWk
role: admin
date: 2024-12-18T16:20:04+01:00
id: 6dbb6d56-a6b7-467b-8341-3d8112a73684
position:
pageIndex: 1
x: "73.3181571571"
y: "27.272727272727"
type: comment
replies: [ ]
-
location:
page:
uri: >
projects/miss-dior-blooming-bouquet/proposal
title: Offre commerciale
project:
title: Miss Dior Blooming Bouquet
uri: projects/miss-dior-blooming-bouquet
dialogUri: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0'
file:
uuid: file://3vTh1tMFeFM2JxaN
url: >
http://localhost:8888/media/pages/projects/miss-dior-blooming-bouquet/proposal/788ddebfe3-1731941917/des-textos-revelent-comment-bfm-sest-mise-au-service-de-sarkozy-le-boss.pdf
text: est
author:
name: Adrien Payet
email: adrien.payet@outlook.com
uuid: user://WWjXgPWk
role: admin
date: 2024-12-18T16:23:42+01:00
id: 5b2d93f9-fc44-4a69-955a-bf282fba8966
position:
pageIndex: 1
x: '43.56742057598'
y: '65.340909090909'
type: comment
replies: [ ]
Comments:
----

View file

@ -5,21 +5,28 @@ namespace adrienpayet\D2P\data;
class Position
{
public int $pageIndex;
public float $x;
public float $y;
public ?float $x = null;
public ?float $y = null;
public function __construct(array $data)
{
$this->pageIndex = $data['pageIndex'];
$this->x = (float) $data['x'];
$this->y = (float) $data['y'];
if (isset($data["x"])) {
$this->x = (float) $data['x'];
$this->y = (float) $data['y'];
}
}
public function toArray() {
return [
$array = [
"pageIndex" => $this->pageIndex,
"x" => $this->x,
"y" => $this->y,
];
if ($this->x) {
$array["x"] = $this->x;
$array["y"] = $this->y;
}
return $array;
}
}

View file

@ -8,6 +8,7 @@ class Location
protected ?string $dialogUri = null;
protected ProjectDetails $project;
protected ?FileDetails $file = null;
protected ?string $parentCommentId = null;
public function __construct(array $data)
{
@ -18,6 +19,17 @@ class Location
if (isset($data['file'])) {
$this->file = new FileDetails($data["file"]);
}
if (isset($data["parentCommentId"])) {
$this->parentCommentId();
}
}
public function setParentCommentId($id) {
$this->parentCommentId = $id;
}
public function parentId() {
return $this->parentCommentId;
}
public function toArray() {
@ -28,6 +40,9 @@ class Location
if ($this->dialogUri) {
$array["dialogUri"] = $this->dialogUri;
}
if ($this->file) {
$array["file"] = $this->file;
}

View file

@ -42,8 +42,6 @@ return [
"type" => "comment",
];
$user->sendNotification($project, $commentData);
$newComment = new Comment($commentData);
$comments[] = $newComment->toArray();

View file

@ -9,36 +9,40 @@ return [
$json = file_get_contents('php://input');
$data = json_decode($json);
$parsedUrl = parse_url($data->path);
$parsedUrl = parse_url($data->dialogUri);
$query = $parsedUrl['query'] ?? null;
parse_str($query, $queryParams);
$stepSlug = $queryParams['dialog'] ?? null;
$targetPageUri = $stepSlug ? $parsedUrl['path'] . '/' . $stepSlug : $parsedUrl['path'];
$project = page($parsedUrl['path']);
$page = page($targetPageUri);
$file = $page->file($data->fileName);
$user = kirby()->user($data->userUuid);
$user = kirby()->user($data->userUuid);
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
$data = [
'href' => $data->path,
'page' => $page,
'parentId' => $data->parentId,
'file' => $file,
'position' => [
'pageIndex' => $data->position->pageIndex,
$replyData = [
"location" => [
"page" => $page,
"project" => $project,
"dialogUri" => $data->dialogUri,
"file" => $file,
],
'text' => $data->text,
'author' => $user,
'date' => (string) $data->date,
'id' => $data->id,
'type' => 'comment'
"parentId" => $data->parentId,
"position" => [
"pageIndex" => $data->position->pageIndex,
],
"date" => (string) $data->date,
"text" => $data->text,
"author" => kirby()->user(),
"id" => Str::uuid(),
"type" => "comment",
];
$newReply = new Reply($data);
$newReply = new Reply($replyData);
foreach ($comments as &$comment) {
if ($comment['id'] === $newReply->parentId()) {
@ -50,7 +54,7 @@ return [
'comments' => $comments
]);
$user->sendNotification($page->parent(), $newReply->toArray());
$user->sendNotification($project, $replyData);
return getFileData($newFile);
}

View file

@ -3,14 +3,16 @@
namespace adrienpayet\comments;
use adrienpayet\D2P\data\location\Location;
use adrienpayet\D2P\data\Author;
use adrienpayet\D2P\data\Position;
class BaseComment {
protected string $type;
protected Location $location;
protected string $text;
protected Author $author;
protected string $text;
protected string $date;
protected string $id;
protected Position $position;
public function __construct($data) {
$this->location = new Location($data["location"]);
@ -18,11 +20,13 @@ class BaseComment {
$this->author = new Author($data["author"]);
$this->date = $data["date"];
$this->id = $data["id"];
$this->position = new Position($data['position']);
}
public function toArray() {
return [
"location" => $this->location->toArray(),
"position" => $this->position->toArray(),
"text" => $this->text,
"author" => $this->author->toArray(),
"date" => $this->date,

View file

@ -1,24 +1,18 @@
<?php
namespace adrienpayet\comments;
use adrienpayet\D2P\data\Position;
class Comment extends BaseComment
{
protected ?Position $position = null;
protected string $type = "comment";
protected array $replies = [];
public function __construct($data) {
parent::__construct($data);
if (isset($data["position"])) {
$this->position = new Position($data['position']);
}
}
public function toArray() {
$array = parent::toArray();
$array['position'] = $this->position;
$array['type'] = $this->type;
$array['replies'] = $this->replies;

View file

@ -3,21 +3,20 @@ namespace adrienpayet\comments;
class Reply extends BaseComment {
protected $parentId;
protected string $type = "comment-reply";
public function __construct($data) {
parent::__construct($data);
$this->parentId = $data['parentId'];
$this->location->setParentCommentId($data["parentId"]);
}
public function parentId() {
return $this->parentId;
return $this->location->parentId();
}
public function toArray() {
$array = parent::toArray();
$array['parentId'] = $this->parentId;
$array['type'] = $this->type;
return $array;
}

View file

@ -36,6 +36,11 @@ const draftComment = ref(null);
const isViewerDisabled = ref(false);
watch(openedFile, () => {
removeCommentMarkers();
setCommentMarkers();
});
watch(isCommentsOpen, (newVal) => {
if (newVal) {
setCommentMarkers();