diff --git a/public/site/plugins/classes/location/FileDetails.php b/public/site/plugins/classes/location/FileDetails.php index ec2fa68..e96b84a 100644 --- a/public/site/plugins/classes/location/FileDetails.php +++ b/public/site/plugins/classes/location/FileDetails.php @@ -7,17 +7,20 @@ class FileDetails { public string $uuid; public string $url; + public string $type; public function __construct(Kirby\Cms\File $data) { $this->uuid = (string) $data->uuid(); $this->url = (string) $data->url(); + $this->type = (string) $data->type(); } public function toArray() { return [ "uuid" => $this->uuid, - "url" => $this->url + "url" => $this->url, + "type" => $this->type ]; } } diff --git a/public/site/plugins/classes/location/Location.php b/public/site/plugins/classes/location/Location.php index bc91c0c..b5649c5 100644 --- a/public/site/plugins/classes/location/Location.php +++ b/public/site/plugins/classes/location/Location.php @@ -5,16 +5,16 @@ namespace adrienpayet\D2P\data\location; class Location { protected PageDetails $page; - protected ?string $dialogUri = null; - protected ProjectDetails $project; + // protected ?string $dialogUri = null; + // protected ProjectDetails $project; protected ?FileDetails $file = null; protected ?array $parent = null; public function __construct(array $data) { $this->page = new PageDetails($data["page"]); - $this->dialogUri = $data["dialogUri"]; - $this->project = new ProjectDetails($data["project"]); + // $this->dialogUri = $data["dialogUri"]; + // $this->project = new ProjectDetails($data["project"]); if (isset($data['file'])) { $this->file = new FileDetails($data["file"]); @@ -33,12 +33,12 @@ class Location public function toArray() { $array = [ "page" => $this->page->toArray(), - "project" => $this->project->toArray(), + // "project" => $this->project->toArray(), ]; - if ($this->dialogUri) { - $array["dialogUri"] = $this->dialogUri; - } + // if ($this->dialogUri) { + // $array["dialogUri"] = $this->dialogUri; + // } if ($this->file) { $array["file"] = $this->file; diff --git a/public/site/plugins/classes/location/PageDetails.php b/public/site/plugins/classes/location/PageDetails.php index 1a38637..738a28c 100644 --- a/public/site/plugins/classes/location/PageDetails.php +++ b/public/site/plugins/classes/location/PageDetails.php @@ -14,6 +14,8 @@ class PageDetails public function toArray() { return [ + "uuid" => (string) $this->page->uuid(), + "template" => (string) $this->page->template(), "uri" => (string) $this->page->uri(), "title" => (string) $this->page->title(), ]; diff --git a/public/site/plugins/comments/routes/create.php b/public/site/plugins/comments/routes/create.php index 96cf559..794a454 100644 --- a/public/site/plugins/comments/routes/create.php +++ b/public/site/plugins/comments/routes/create.php @@ -21,7 +21,6 @@ return [ "location" => [ "page" => $page, "project" => $project, - "dialogUri" => $data->dialogUri, "file" => $file ], "position" => [ diff --git a/public/site/plugins/comments/routes/delete.php b/public/site/plugins/comments/routes/delete.php index 2e2a522..3146f43 100644 --- a/public/site/plugins/comments/routes/delete.php +++ b/public/site/plugins/comments/routes/delete.php @@ -8,12 +8,11 @@ return [ $data = json_decode($json); $page = page($data->location->page->uri); - $project = page($data->location->project->uri); + $file = $page->file($data->location->file->uuid); - $isReply = $data->location->parent->id ?? false; - $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); + $isReply = $data->location->parent->id ?? false; foreach ($comments as $key => &$comment) { if ($isReply) { if ($comment['id'] === $data->location->parent->id) { @@ -39,6 +38,7 @@ return [ echo json_encode(getFileData($newFile)); + $project = $page->parents()->findBy("template", "project"); $project->deleteNotification($data->id); exit; diff --git a/public/site/plugins/comments/routes/reply.php b/public/site/plugins/comments/routes/reply.php index b4d2d00..68aeebd 100644 --- a/public/site/plugins/comments/routes/reply.php +++ b/public/site/plugins/comments/routes/reply.php @@ -10,10 +10,8 @@ return [ $data = json_decode($json); $page = page($data->fileParentUri); - $project = $page->parent()->template() == "project" ? $page->parent() : $page->parent()->parent(); + $file = $page->file($data->fileName); - $user = kirby()->user($data->userUuid); - $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); foreach ($comments as &$comment) { @@ -22,8 +20,6 @@ return [ $replyData = [ "location" => [ "page" => $page, - "project" => $project, - "dialogUri" => $data->dialogUri, "file" => $file, "parent" => $comment ], @@ -45,7 +41,8 @@ return [ 'comments' => $comments ]); - $user->sendNotification($project, $replyData); + $project = $page->parents()->findBy("template", "project"); + $project->createNotification($replyData); return getFileData($newFile); } diff --git a/public/site/plugins/notifications/routes/read.php b/public/site/plugins/notifications/routes/read.php index 213ca8f..430c0dd 100644 --- a/public/site/plugins/notifications/routes/read.php +++ b/public/site/plugins/notifications/routes/read.php @@ -8,7 +8,7 @@ return [ $data = json_decode($json); try { - $project = page($data->projectUuid); + $project = page($data->projectId); $project->readNotification($data->notificationId); return json_encode([ "status" => "success" diff --git a/public/site/templates/industrial-ideation.php b/public/site/templates/industrial-ideation.php new file mode 100644 index 0000000..e69de29 diff --git a/src/components/comments/Comment.vue b/src/components/comments/Comment.vue index b9ba749..69317fa 100644 --- a/src/components/comments/Comment.vue +++ b/src/components/comments/Comment.vue @@ -85,6 +85,7 @@ import { useApiStore } from "../../stores/api"; import { useDialogStore } from "../../stores/dialog"; import { computed, onMounted, ref, useTemplateRef } from "vue"; import { storeToRefs } from "pinia"; +import { usePageStore } from "../../stores/page"; dayjs.locale("fr"); @@ -102,6 +103,7 @@ const { activeTracks, openedComment } = storeToRefs(useDialogStore()); const draftText = ref(comment.text); const editField = ref(null); const commentNode = useTemplateRef("comment-node"); +const { page } = storeToRefs(usePageStore()); let correspondingMarker = null; // Functions @@ -143,7 +145,7 @@ function handleClick() { async function read() { if (getStatus.value !== "unread") return; try { - const newNotification = await api.readNotification(comment); + const newNotification = await api.readNotification(comment, page.value.uri); console.log(newNotification); userStore.readNotification(comment.id); } catch (error) { diff --git a/src/components/comments/Comments.vue b/src/components/comments/Comments.vue index 5ca88a6..24501cf 100644 --- a/src/components/comments/Comments.vue +++ b/src/components/comments/Comments.vue @@ -179,7 +179,6 @@ function handleSubmit(event = null) { } const date = dayjs().format(); const newComment = { - dialogUri: route.fullPath, fileName: openedFile.value ? openedFile.value.name : false, userUuid: user.uuid, text: draftComment.value.text, @@ -202,7 +201,7 @@ function handleSubmit(event = null) { async function replyComment(newComment) { newComment.parentId = openedComment.value.id; - const matchFileParentUri = openedComment.value.location.file.url.match( + const matchFileParentUri = openedFile.value.url.match( /projects\/.*?(?=\/[^/]+\/[^/]+$)/ ); newComment.fileParentUri = matchFileParentUri ? matchFileParentUri[0] : null; @@ -224,14 +223,16 @@ async function addComment(newComment) { resetDraftComment(); isAddOpen.value = false; dialog.updateFile(newFile); - activeTracks.value = activeTracks.value.map((track) => { - if (track.files) { - track.files = track.files.map((file) => - file.uuid === newFile.uuid ? newFile : file - ); - } - return track; - }); + if (activeTracks.value) { + activeTracks.value = activeTracks.value.map((track) => { + if (track.files) { + track.files = track.files.map((file) => + file.uuid === newFile.uuid ? newFile : file + ); + } + return track; + }); + } } function resetDraftComment() { @@ -318,11 +319,15 @@ function openComment(comment) { openedComment.value = comment; if (activeTracks.value?.length === 1) { - openedFile.value = activeTracks.value[0].files.find( - (file) => file.uuid === openedComment.value.location.file.uuid - ); + showCorrespondingView(); } } + +function showCorrespondingView() { + openedFile.value = activeTracks.value[0].files.find( + (file) => file.uuid === openedComment.value.location.file.uuid + ); +}