diff --git a/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt b/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt index 16c313b..81ca75f 100644 --- a/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt +++ b/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt @@ -20,7 +20,46 @@ m2ucagze: position: x: 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 user: name: Adrien Payet diff --git a/public/site/plugins/comments/index.php b/public/site/plugins/comments/index.php index fdb6655..f4d8e7f 100644 --- a/public/site/plugins/comments/index.php +++ b/public/site/plugins/comments/index.php @@ -5,5 +5,6 @@ Kirby::plugin('adrienpayet/pdc-comments', [ require(__DIR__ . '/routes/create.php'), require(__DIR__ . '/routes/update.php'), require(__DIR__ . '/routes/delete.php'), + require(__DIR__ . '/routes/reply.php'), ] ]); diff --git a/public/site/plugins/comments/routes/reply.php b/public/site/plugins/comments/routes/reply.php index f279327..da96502 100644 --- a/public/site/plugins/comments/routes/reply.php +++ b/public/site/plugins/comments/routes/reply.php @@ -1,7 +1,7 @@ '(:all)create-comment.json', + 'pattern' => '(:all)reply-comment.json', 'method' => 'POST', 'action' => function () { $json = file_get_contents('php://input'); @@ -17,7 +17,7 @@ return [ $newComment = [ 'pageUri' => $data->pageUri, 'fileUuid' => (string) $file->uuid(), - 'filePageTarget' => $data->targetPage, + 'filePageIndex' => $data->filePageIndex, 'text' => $data->text, 'user' => [ 'name' => (string) $user->name(), diff --git a/src/components/comments/Comments.vue b/src/components/comments/Comments.vue index 72fdf74..085b76b 100644 --- a/src/components/comments/Comments.vue +++ b/src/components/comments/Comments.vue @@ -16,12 +16,18 @@ - -
+ +
@@ -57,7 +63,7 @@ action="" method="post" class="flow | bg-white-20 | p-12 | rounded-xl" - @submit="addComment" + @submit="handleSubmit" > @@ -107,10 +113,10 @@ const isAddOpen = ref(false); const emits = defineEmits(["update:file"]); // Functions -async function addComment(event) { +function handleSubmit(event) { event.preventDefault(); const date = dayjs().format(); - const comment = { + const newComment = { pageUri: page.uri + "/client-brief", filePageIndex: currentPageIndex, fileName: file.name, @@ -119,7 +125,24 @@ async function addComment(event) { date, 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 = ""; isAddOpen.value = false; emits("update:file", newFile); diff --git a/src/stores/api.js b/src/stores/api.js index 4de0fe5..87661da 100644 --- a/src/stores/api.js +++ b/src/stores/api.js @@ -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) { const headers = { method: "POST", @@ -175,6 +198,7 @@ export const useApiStore = defineStore("api", () => { fetchData, fetchRoute, addComment, + replyComment, readNotification, }; });