2024-10-23 09:48:27 +02:00
|
|
|
<template>
|
|
|
|
|
<aside id="comments-container" aria-labelledby="comments-label">
|
|
|
|
|
<h2 id="comments-label" class="sr-only">Commentaires</h2>
|
|
|
|
|
<div class="comments | flow">
|
2024-10-29 11:18:17 +01:00
|
|
|
<template v-if="!openedComment">
|
2024-10-29 12:11:50 +01:00
|
|
|
<!-- TODO: faire un composant comment -->
|
2024-10-29 11:18:17 +01:00
|
|
|
<article
|
|
|
|
|
v-for="(comment, commentIndex) in Object.values(comments).reverse()"
|
|
|
|
|
:key="commentIndex"
|
|
|
|
|
class="comment | flow"
|
|
|
|
|
:data-status="setStatus(comment)"
|
|
|
|
|
@click="open(comment)"
|
|
|
|
|
>
|
|
|
|
|
<header>
|
|
|
|
|
<p>
|
|
|
|
|
<strong>{{ comment.user.name ?? comment.user.email }}</strong>
|
|
|
|
|
<span class="comment__id">#{{ commentIndex + 1 }}</span> •
|
|
|
|
|
<span class="comment__page">Page {{ pageIndex }}</span>
|
|
|
|
|
<time :datetime="dayjs(comment.date).format('YYYY-MM-DD')">{{
|
|
|
|
|
formatDate(comment.date)
|
|
|
|
|
}}</time>
|
|
|
|
|
</p>
|
|
|
|
|
</header>
|
|
|
|
|
<p class="comment__body">
|
|
|
|
|
{{ comment.text }}
|
2024-10-23 09:48:27 +02:00
|
|
|
</p>
|
2024-10-29 12:11:50 +01:00
|
|
|
<!-- TODO: à dynamiser (affichage ou non si replies + nombre de replies)-->
|
|
|
|
|
<footer class="comment__replies">
|
|
|
|
|
<span>1 réponse</span>
|
|
|
|
|
</footer>
|
2024-10-29 11:18:17 +01:00
|
|
|
</article>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-else>
|
2024-10-29 12:11:50 +01:00
|
|
|
<!-- TODO: mettre la bonne cible pour to: -->
|
|
|
|
|
<router-link
|
|
|
|
|
:to="'/' + page.parent"
|
|
|
|
|
class="btn | justify-start w-full | bg-white-10 text-white | px-8"
|
|
|
|
|
data-icon="chevron-single-left"
|
|
|
|
|
>
|
|
|
|
|
<span>Retour à la liste</span>
|
|
|
|
|
</router-link>
|
|
|
|
|
<!-- TODO: utiliser le composant comment ici -->
|
|
|
|
|
<article
|
|
|
|
|
class="comment"
|
|
|
|
|
data-opened="true"
|
|
|
|
|
>
|
|
|
|
|
<header>
|
|
|
|
|
<p>
|
|
|
|
|
<strong>{{ openedComment.user.name ?? openedComment.user.email }}</strong>
|
|
|
|
|
<span class="comment__id">#{{ commentIndex + 1 }}</span> •
|
|
|
|
|
<span class="comment__page">Page {{ pageIndex }}</span>
|
|
|
|
|
<time :datetime="dayjs(openedComment.date).format('YYYY-MM-DD')">{{
|
|
|
|
|
formatDate(openedComment.date)
|
|
|
|
|
}}</time>
|
|
|
|
|
</p>
|
|
|
|
|
</header>
|
|
|
|
|
<p class="comment__body">
|
|
|
|
|
{{ openedComment.text }}
|
|
|
|
|
</p>
|
|
|
|
|
<footer class="comment__replies">
|
|
|
|
|
<span>1 réponse</span>
|
|
|
|
|
</footer>
|
2024-10-29 11:18:17 +01:00
|
|
|
</article>
|
|
|
|
|
<div class="replies">
|
2024-10-29 12:11:50 +01:00
|
|
|
<!-- TODO: utiliser le composant comment ici -->
|
|
|
|
|
<article
|
|
|
|
|
v-for="comment in openedComment.replies"
|
|
|
|
|
class="comment reply"
|
|
|
|
|
>
|
|
|
|
|
<header>
|
|
|
|
|
<p>
|
|
|
|
|
<strong>{{ comment.user.name ?? comment.user.email }}</strong>
|
|
|
|
|
<span class="comment__id">#{{ commentIndex + 1 }}</span> •
|
|
|
|
|
<span class="comment__page">Page {{ pageIndex }}</span>
|
|
|
|
|
<time :datetime="dayjs(comment.date).format('YYYY-MM-DD')">{{
|
|
|
|
|
formatDate(comment.date)
|
|
|
|
|
}}</time>
|
|
|
|
|
</p>
|
|
|
|
|
</header>
|
|
|
|
|
<p class="comment__body">
|
|
|
|
|
{{ comment.text }}
|
|
|
|
|
</p>
|
|
|
|
|
</article>
|
2024-10-29 11:18:17 +01:00
|
|
|
</div>
|
|
|
|
|
</template>
|
2024-10-23 09:48:27 +02:00
|
|
|
</div>
|
|
|
|
|
<button
|
2024-10-29 12:11:50 +01:00
|
|
|
v-if="!openedComment && !isAddOpen"
|
2024-10-29 11:12:57 +01:00
|
|
|
id="create-comment"
|
2024-10-23 09:48:27 +02:00
|
|
|
class="btn btn--white-20 | w-full"
|
|
|
|
|
@click="isAddOpen = true"
|
|
|
|
|
>
|
|
|
|
|
Ajouter un commentaire
|
|
|
|
|
</button>
|
2024-10-29 12:11:50 +01:00
|
|
|
<button
|
|
|
|
|
v-if="openedComment && !isReplyOpen"
|
|
|
|
|
id="reply-comment"
|
|
|
|
|
class="btn btn--white-20 | justify-start w-full | text-white-50"
|
|
|
|
|
@click="isReplyOpen = true"
|
|
|
|
|
>
|
|
|
|
|
Répondre…
|
|
|
|
|
</button>
|
2024-10-23 09:48:27 +02:00
|
|
|
|
|
|
|
|
<form
|
|
|
|
|
v-if="isAddOpen"
|
|
|
|
|
action=""
|
|
|
|
|
method="post"
|
2024-10-29 12:11:50 +01:00
|
|
|
class="flow | bg-white-20 | p-12 | rounded-xl"
|
2024-10-23 09:48:27 +02:00
|
|
|
@submit="addComment"
|
|
|
|
|
>
|
|
|
|
|
<label class="sr-only" for="comment">Votre commentaire</label>
|
|
|
|
|
<textarea
|
|
|
|
|
name="comment"
|
|
|
|
|
id="comment"
|
2024-10-29 12:11:50 +01:00
|
|
|
placeholder="Ajouter un commentaire…"
|
|
|
|
|
rows="5"
|
2024-10-23 09:48:27 +02:00
|
|
|
class="text-sm | rounded-lg bg-black p-12"
|
|
|
|
|
v-model="newCommentText"
|
|
|
|
|
></textarea>
|
|
|
|
|
<footer class="flex">
|
2024-10-29 12:11:50 +01:00
|
|
|
<input type="submit" class="btn btn--tranparent" />
|
|
|
|
|
<button class="btn btn--white-10" @click="closeAddField()">
|
2024-10-23 15:45:04 +02:00
|
|
|
Annuler
|
|
|
|
|
</button>
|
2024-10-23 09:48:27 +02:00
|
|
|
</footer>
|
|
|
|
|
</form>
|
|
|
|
|
</aside>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2024-10-23 11:32:51 +02:00
|
|
|
import dayjs from "dayjs";
|
|
|
|
|
import "dayjs/locale/fr";
|
|
|
|
|
import uniqid from "uniqid";
|
2024-10-23 09:48:27 +02:00
|
|
|
import { ref } from "vue";
|
|
|
|
|
import { useUserStore } from "../../stores/user";
|
2024-10-23 11:32:51 +02:00
|
|
|
import { usePageStore } from "../../stores/page";
|
2024-10-28 17:50:40 +01:00
|
|
|
import { useApiStore } from "../../stores/api";
|
2024-10-23 11:32:51 +02:00
|
|
|
|
|
|
|
|
dayjs.locale("fr");
|
2024-10-23 09:48:27 +02:00
|
|
|
|
2024-10-23 11:32:51 +02:00
|
|
|
const { currentPageIndex, file, comments } = defineProps({
|
|
|
|
|
currentPageIndex: Number,
|
|
|
|
|
file: Object,
|
|
|
|
|
comments: Object,
|
2024-10-23 09:48:27 +02:00
|
|
|
});
|
2024-10-29 11:18:17 +01:00
|
|
|
|
2024-10-23 09:48:27 +02:00
|
|
|
const { user } = useUserStore();
|
2024-10-23 11:32:51 +02:00
|
|
|
const { page } = usePageStore();
|
2024-10-28 17:50:40 +01:00
|
|
|
const api = useApiStore();
|
2024-10-23 09:48:27 +02:00
|
|
|
|
2024-10-29 11:18:17 +01:00
|
|
|
const openedComment = ref(null);
|
|
|
|
|
|
2024-10-23 09:48:27 +02:00
|
|
|
const newCommentText = ref("");
|
|
|
|
|
const isAddOpen = ref(false);
|
2024-10-23 15:45:04 +02:00
|
|
|
const emits = defineEmits(["update:file"]);
|
2024-10-23 09:48:27 +02:00
|
|
|
|
|
|
|
|
// Functions
|
2024-10-28 17:50:40 +01:00
|
|
|
async function addComment(event) {
|
2024-10-23 09:48:27 +02:00
|
|
|
event.preventDefault();
|
2024-10-23 11:32:51 +02:00
|
|
|
const date = dayjs().format();
|
2024-10-23 09:48:27 +02:00
|
|
|
const comment = {
|
2024-10-23 11:32:51 +02:00
|
|
|
pageUri: page.uri + "/client-brief",
|
|
|
|
|
targetPage: currentPageIndex,
|
|
|
|
|
fileName: file.name,
|
2024-10-23 09:48:27 +02:00
|
|
|
userUuid: user.uuid,
|
|
|
|
|
text: newCommentText.value,
|
2024-10-23 11:32:51 +02:00
|
|
|
date,
|
|
|
|
|
id: uniqid(),
|
|
|
|
|
};
|
2024-10-28 17:50:40 +01:00
|
|
|
const newFile = await api.addComment(comment);
|
|
|
|
|
newCommentText.value = "";
|
|
|
|
|
isAddOpen.value = false;
|
2024-10-29 11:12:57 +01:00
|
|
|
emits("update:file", newFile);
|
2024-10-23 11:32:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatDate(date) {
|
|
|
|
|
const todayNumber = parseInt(dayjs().format("YYMMD"));
|
|
|
|
|
const dateNumber = parseInt(dayjs(date).format("YYMMD"));
|
|
|
|
|
|
|
|
|
|
if (dateNumber === todayNumber) {
|
|
|
|
|
return "Aujourd'hui";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dateNumber === todayNumber - 1) {
|
|
|
|
|
return "hier";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dayjs(date).format("D MMM YY");
|
2024-10-23 09:48:27 +02:00
|
|
|
}
|
2024-10-23 15:45:04 +02:00
|
|
|
|
|
|
|
|
function closeAddField() {
|
|
|
|
|
isAddOpen.value = false;
|
|
|
|
|
newCommentText.value = "";
|
|
|
|
|
}
|
2024-10-23 16:19:33 +02:00
|
|
|
|
|
|
|
|
function setStatus(comment) {
|
2024-10-23 16:29:41 +02:00
|
|
|
try {
|
2024-10-28 17:50:40 +01:00
|
|
|
if (!user?.notifications?.comments[comment.id].isRead) {
|
2024-10-23 16:29:41 +02:00
|
|
|
return "unread";
|
|
|
|
|
} else {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
2024-10-23 16:19:33 +02:00
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-28 17:50:40 +01:00
|
|
|
|
|
|
|
|
async function readNotification(notificationId) {
|
|
|
|
|
const newNotifications = await api.readNotification(
|
|
|
|
|
user.uuid,
|
|
|
|
|
"comments",
|
|
|
|
|
notificationId
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
user.notifications = newNotifications;
|
|
|
|
|
}
|
2024-10-23 09:48:27 +02:00
|
|
|
</script>
|