reply comment working

This commit is contained in:
isUnknown 2024-10-29 16:51:31 +01:00
parent 2af56989c9
commit 8ed7331b61
5 changed files with 101 additions and 14 deletions

View file

@ -20,7 +20,46 @@ m2ucagze:
position: position:
x: null x: null
y: null y: null
replies: [ ] replies:
m2umbiak:
pageUri: >
projects/miss-dior-blooming-bouquet/client-brief
fileUuid: file://s0lNtRA0Z7ybTCWG
filePageIndex: 1
text: réponse
user:
name: Adrien Payet
email: adrien.payet@outlook.com
uuid: user://WWjXgPWk
role: admin
date: 2024-10-29T16:44:08+01:00
id: m2umbiak
m2umh277:
pageUri: >
projects/miss-dior-blooming-bouquet/client-brief
fileUuid: file://s0lNtRA0Z7ybTCWG
filePageIndex: 1
text: deuxième réponse
user:
name: Adrien Payet
email: adrien.payet@outlook.com
uuid: user://WWjXgPWk
role: admin
date: 2024-10-29T16:48:27+01:00
id: m2umh277
m2umjmbx:
pageUri: >
projects/miss-dior-blooming-bouquet/client-brief
fileUuid: file://s0lNtRA0Z7ybTCWG
filePageIndex: 1
text: troisième commentaire
user:
name: Adrien Payet
email: adrien.payet@outlook.com
uuid: user://WWjXgPWk
role: admin
date: 2024-10-29T16:50:27+01:00
id: m2umjmbx
text: com1 text: com1
user: user:
name: Adrien Payet name: Adrien Payet

View file

@ -5,5 +5,6 @@ Kirby::plugin('adrienpayet/pdc-comments', [
require(__DIR__ . '/routes/create.php'), require(__DIR__ . '/routes/create.php'),
require(__DIR__ . '/routes/update.php'), require(__DIR__ . '/routes/update.php'),
require(__DIR__ . '/routes/delete.php'), require(__DIR__ . '/routes/delete.php'),
require(__DIR__ . '/routes/reply.php'),
] ]
]); ]);

View file

@ -1,7 +1,7 @@
<?php <?php
return [ return [
'pattern' => '(:all)create-comment.json', 'pattern' => '(:all)reply-comment.json',
'method' => 'POST', 'method' => 'POST',
'action' => function () { 'action' => function () {
$json = file_get_contents('php://input'); $json = file_get_contents('php://input');
@ -17,7 +17,7 @@ return [
$newComment = [ $newComment = [
'pageUri' => $data->pageUri, 'pageUri' => $data->pageUri,
'fileUuid' => (string) $file->uuid(), 'fileUuid' => (string) $file->uuid(),
'filePageTarget' => $data->targetPage, 'filePageIndex' => $data->filePageIndex,
'text' => $data->text, 'text' => $data->text,
'user' => [ 'user' => [
'name' => (string) $user->name(), 'name' => (string) $user->name(),

View file

@ -16,12 +16,18 @@
<button <button
class="btn | justify-start w-full | bg-white-10 text-white | px-8" class="btn | justify-start w-full | bg-white-10 text-white | px-8"
data-icon="chevron-single-left" data-icon="chevron-single-left"
@click="openedComment = null" @click="
openedComment = null;
isAddOpen = false;
"
> >
<span>Retour à la liste</span> <span>Retour à la liste</span>
</button> </button>
<Comment :comment="openedComment" /> <Comment :comment="openedComment" data-opened="true" />
<div v-if="openedComment?.replies?.length > 0" class="replies"> <div
v-if="Object.values(openedComment.replies).length > 0"
class="replies"
>
<Comment <Comment
v-for="(reply, commentIndex) in Object.values( v-for="(reply, commentIndex) in Object.values(
openedComment.replies openedComment.replies
@ -36,7 +42,7 @@
<template v-else> état aucun commentaire </template> <template v-else> état aucun commentaire </template>
</div> </div>
<button <button
v-if="!openedComment && !isAddOpen" v-if="!openedComment"
id="create-comment" id="create-comment"
class="btn btn--white-20 | w-full" class="btn btn--white-20 | w-full"
@click="isAddOpen = true" @click="isAddOpen = true"
@ -44,10 +50,10 @@
Ajouter un commentaire Ajouter un commentaire
</button> </button>
<button <button
v-else v-else-if="openedComment && !isAddOpen"
id="reply-comment" id="reply-comment"
class="btn btn--white-20 | justify-start w-full | text-white-50" class="btn btn--white-20 | justify-start w-full | text-white-50"
@click="isReplyOpen = true" @click="isAddOpen = true"
> >
Répondre Répondre
</button> </button>
@ -57,7 +63,7 @@
action="" action=""
method="post" method="post"
class="flow | bg-white-20 | p-12 | rounded-xl" class="flow | bg-white-20 | p-12 | rounded-xl"
@submit="addComment" @submit="handleSubmit"
> >
<label class="sr-only" for="comment">Votre commentaire</label> <label class="sr-only" for="comment">Votre commentaire</label>
<textarea <textarea
@ -70,7 +76,7 @@
></textarea> ></textarea>
<footer class="flex"> <footer class="flex">
<input type="submit" class="btn btn--tranparent" /> <input type="submit" class="btn btn--tranparent" />
<button class="btn btn--white-10" @click="closeAddField()"> <button class="btn btn--white-10" @click="isAddOpen = false">
Annuler Annuler
</button> </button>
</footer> </footer>
@ -107,10 +113,10 @@ const isAddOpen = ref(false);
const emits = defineEmits(["update:file"]); const emits = defineEmits(["update:file"]);
// Functions // Functions
async function addComment(event) { function handleSubmit(event) {
event.preventDefault(); event.preventDefault();
const date = dayjs().format(); const date = dayjs().format();
const comment = { const newComment = {
pageUri: page.uri + "/client-brief", pageUri: page.uri + "/client-brief",
filePageIndex: currentPageIndex, filePageIndex: currentPageIndex,
fileName: file.name, fileName: file.name,
@ -119,7 +125,24 @@ async function addComment(event) {
date, date,
id: uniqid(), id: uniqid(),
}; };
const newFile = await api.addComment(comment); if (openedComment.value) {
replyComment(newComment);
} else {
addComment(newComment);
}
}
async function replyComment(newComment) {
newComment.parentId = openedComment.value.id;
const newFile = await api.replyComment(newComment);
newCommentText.value = "";
isAddOpen.value = false;
openedComment.value = newFile.comments[openedComment.value.id];
emits("update:file", newFile);
}
async function addComment(newComment) {
const newFile = await api.addComment(newComment);
newCommentText.value = ""; newCommentText.value = "";
isAddOpen.value = false; isAddOpen.value = false;
emits("update:file", newFile); emits("update:file", newFile);

View file

@ -144,6 +144,29 @@ export const useApiStore = defineStore("api", () => {
} }
} }
async function replyComment(comment) {
const headers = {
method: "POST",
body: JSON.stringify(comment),
};
try {
const response = await fetch("/reply-comment.json", headers);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const newFile = await response.json();
return newFile;
} catch (error) {
console.error(
"Une erreur s'est produite lors de l'ajout de la réponse' :",
commentaire,
error
);
throw error;
}
}
async function readNotification(userUuid, group, notificationId) { async function readNotification(userUuid, group, notificationId) {
const headers = { const headers = {
method: "POST", method: "POST",
@ -175,6 +198,7 @@ export const useApiStore = defineStore("api", () => {
fetchData, fetchData,
fetchRoute, fetchRoute,
addComment, addComment,
replyComment,
readNotification, readNotification,
}; };
}); });