2024-10-29 16:13:07 +01:00
|
|
|
<template>
|
|
|
|
|
<article class="comment | flow" :data-status="setStatus(comment)">
|
|
|
|
|
<header>
|
|
|
|
|
<p>
|
2024-10-30 12:15:28 +01:00
|
|
|
<strong>{{ comment.author.name ?? comment.author.email }}</strong>
|
2024-10-29 16:13:07 +01:00
|
|
|
<template v-if="commentIndex">
|
|
|
|
|
<span class="comment__id">#{{ commentIndex }}</span>
|
|
|
|
|
•
|
|
|
|
|
</template>
|
2024-10-29 17:26:23 +01:00
|
|
|
<span class="comment__page">Page {{ comment.file.pageIndex }}</span>
|
2024-10-29 16:13:07 +01:00
|
|
|
<time :datetime="dayjs(comment.date).format('YYYY-MM-DD')">{{
|
|
|
|
|
formatDate(comment.date)
|
|
|
|
|
}}</time>
|
|
|
|
|
</p>
|
|
|
|
|
</header>
|
|
|
|
|
<p class="comment__body">
|
|
|
|
|
{{ comment.text }}
|
|
|
|
|
</p>
|
|
|
|
|
<footer v-if="comment.replies?.length > 0" class="comment__replies">
|
2024-10-30 15:15:53 +01:00
|
|
|
<p>{{ comment.replies.length }} réponse{{ comment.replies.length > 1 ? 's' : '' }}</p>
|
|
|
|
|
<!-- TODO: n'afficher que s'il s'agit du commentaire de l'utilisateur actuellement connecté -->
|
|
|
|
|
<div class="comment__ctas | mt-8">
|
|
|
|
|
<button class="btn btn--transparent btn--icon btn--sm" data-icon="edit"><span class="sr-only">Éditer</span></button>
|
|
|
|
|
<button class="btn btn--transparent btn--icon btn--sm" data-icon="delete"><span class="sr-only">Supprimer</span></button>
|
|
|
|
|
</div>
|
2024-10-29 16:13:07 +01:00
|
|
|
</footer>
|
|
|
|
|
</article>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
import dayjs from "dayjs";
|
|
|
|
|
import "dayjs/locale/fr";
|
|
|
|
|
|
|
|
|
|
dayjs.locale("fr");
|
|
|
|
|
|
|
|
|
|
const { comment, commentIndex } = defineProps({
|
|
|
|
|
comment: Object,
|
|
|
|
|
commentIndex: Number,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Functions
|
|
|
|
|
function setStatus(comment) {
|
|
|
|
|
try {
|
|
|
|
|
if (!user?.notifications?.comments[comment.id].isRead) {
|
|
|
|
|
return "unread";
|
|
|
|
|
} else {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closeAddField() {
|
|
|
|
|
isAddOpen.value = false;
|
|
|
|
|
newCommentText.value = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function readNotification(notificationId) {
|
|
|
|
|
const newNotifications = await api.readNotification(
|
|
|
|
|
user.uuid,
|
|
|
|
|
"comments",
|
|
|
|
|
notificationId
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
user.notifications = newNotifications;
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2024-10-30 15:15:53 +01:00
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.comments > .comment:not([data-opened="true"]) {
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
|
|
|
|
.comment {
|
|
|
|
|
--flow-space: var(--space-12);
|
|
|
|
|
font-size: var(--text-sm);
|
|
|
|
|
border: var(--border);
|
|
|
|
|
border-width: 2px;
|
|
|
|
|
border-radius: var(--rounded-lg);
|
|
|
|
|
padding: var(--space-12);
|
|
|
|
|
color: var(--color-grey-400);
|
|
|
|
|
}
|
|
|
|
|
.comment header p {
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: var(--space-8);
|
|
|
|
|
}
|
|
|
|
|
.comment header strong,
|
|
|
|
|
.comment footer {
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
color: var(--color-white);
|
|
|
|
|
}
|
|
|
|
|
.comment header time {
|
|
|
|
|
color: var(--color-primary);
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
margin-left: auto;
|
|
|
|
|
}
|
|
|
|
|
.comment[data-status="unread"] {
|
|
|
|
|
background: var(--color-white);
|
|
|
|
|
border-color: var(--color-white);
|
|
|
|
|
color: var(--color-grey-700);
|
|
|
|
|
}
|
|
|
|
|
.comment[data-status="unread"] header p > :first-child::before {
|
|
|
|
|
content: "";
|
|
|
|
|
display: inline-block;
|
|
|
|
|
width: 0.375rem;
|
|
|
|
|
height: 0.375rem;
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
background: var(--color-primary);
|
|
|
|
|
margin-right: var(--space-8);
|
|
|
|
|
margin-bottom: 0.075em;
|
|
|
|
|
}
|
|
|
|
|
.comment[data-status="unread"] header strong,
|
|
|
|
|
.comment[data-status="unread"] footer {
|
|
|
|
|
color: var(--color-black);
|
|
|
|
|
}
|
|
|
|
|
.comment[data-status="unread"] header time {
|
|
|
|
|
color: var(--color-primary);
|
|
|
|
|
}
|
|
|
|
|
.comment[data-opened="true"] {
|
|
|
|
|
border-color: transparent;
|
|
|
|
|
}
|
|
|
|
|
.comment[data-opened="true"] .comment__replies {
|
|
|
|
|
color: var(--color-primary);
|
|
|
|
|
}
|
|
|
|
|
.comment__ctas > * {
|
|
|
|
|
--border-color: transparent;
|
|
|
|
|
margin-right: var(--space-4);
|
|
|
|
|
}
|
|
|
|
|
</style>
|