comments reactive

This commit is contained in:
isUnknown 2024-11-16 12:16:03 +01:00
parent 2c99811caf
commit 82f4aaf904
4 changed files with 19 additions and 66 deletions

View file

@ -27,51 +27,9 @@ Comments:
role: admin role: admin
position: position:
pageIndex: 1 pageIndex: 1
x: "22.956789508989" x: "19.132179426191"
y: "22.586872586873" y: "21.235521235521"
date: 2024-11-16T12:04:11+01:00 date: 2024-11-16T12:15:12+01:00
id: m3k28t8f id: m3k2mztq
type: comment
isRead: false
-
page:
uri: projects/miss-dior-blooming-bouquet
title: Miss Dior Blooming Bouquet
file:
uuid: file://s0lNtRA0Z7ybTCWG
replies: [ ]
text: encore
author:
name: Adrien Payet
email: adrien.payet@outlook.com
uuid: user://WWjXgPWk
role: admin
position:
pageIndex: 1
x: "24.049536437931"
y: "37.451737451737"
date: 2024-11-16T12:04:32+01:00
id: m3k299rb
type: comment
isRead: false
-
page:
uri: projects/miss-dior-blooming-bouquet
title: Miss Dior Blooming Bouquet
file:
uuid: file://s0lNtRA0Z7ybTCWG
replies: [ ]
text: et encore
author:
name: Adrien Payet
email: adrien.payet@outlook.com
uuid: user://WWjXgPWk
role: admin
position:
pageIndex: 1
x: '67.486226863373'
y: '53.088803088803'
date: 2024-11-16T12:05:20+01:00
id: m3k2ab7h
type: comment type: comment
isRead: false isRead: false

View file

@ -52,6 +52,7 @@ import dayjs from "dayjs";
import "dayjs/locale/fr"; import "dayjs/locale/fr";
import { useUserStore } from "../../stores/user"; import { useUserStore } from "../../stores/user";
import { useApiStore } from "../../stores/api"; import { useApiStore } from "../../stores/api";
import { useDialogStore } from "../../stores/dialog";
dayjs.locale("fr"); dayjs.locale("fr");
@ -64,6 +65,7 @@ const emits = defineEmits(["update:file", "close:comment"]);
const { user } = useUserStore(); const { user } = useUserStore();
const api = useApiStore(); const api = useApiStore();
const dialog = useDialogStore();
// Functions // Functions
function setStatus(comment) { function setStatus(comment) {
@ -111,7 +113,7 @@ async function readNotification(notificationId) {
async function deleteComment(event, comment) { async function deleteComment(event, comment) {
event.stopPropagation(); event.stopPropagation();
const newFile = await api.deleteComment(comment); const newFile = await api.deleteComment(comment);
emits("update:file", newFile); dialog.updateFile(newFile);
if (comment.parentId) { if (comment.parentId) {
emits("close:comment"); emits("close:comment");
} }

View file

@ -134,12 +134,6 @@ const sortedReplies = ref(null);
watch(openedComment, (newVal) => { watch(openedComment, (newVal) => {
sortedReplies.value = newVal ? newVal.replies.slice().reverse() : null; sortedReplies.value = newVal ? newVal.replies.slice().reverse() : null;
}); });
watch(
() => comments,
(newVal) => {
sortedComments.value = newVal.reverse();
}
);
watch(isAddOpen, (newVal) => { watch(isAddOpen, (newVal) => {
if (newVal) { if (newVal) {
setTimeout(() => { setTimeout(() => {
@ -191,6 +185,7 @@ async function replyComment(newComment) {
const newFile = await api.replyComment(newComment); const newFile = await api.replyComment(newComment);
newCommentText.value = ""; newCommentText.value = "";
isAddOpen.value = false; isAddOpen.value = false;
dialog.updateFile(newFile);
openedComment.value = newFile.comments.find( openedComment.value = newFile.comments.find(
(item) => item.id === openedComment.value.id (item) => item.id === openedComment.value.id
); );

View file

@ -17,7 +17,7 @@
<VPdfViewer <VPdfViewer
:darkMode="true" :darkMode="true"
:initialThumbnailsVisible="true" :initialThumbnailsVisible="true"
:src="file.url" :src="openedFile.url"
local="fr_FR" local="fr_FR"
@loaded="onPdfLoaded" @loaded="onPdfLoaded"
/> />
@ -42,10 +42,11 @@ import { VPdfViewer, useLicense } from "@vue-pdf-viewer/viewer";
import { ref, watch } from "vue"; import { ref, watch } from "vue";
import { useDialogStore } from "../../../stores/dialog"; import { useDialogStore } from "../../../stores/dialog";
import { useRoute, useRouter } from "vue-router"; import { useRoute, useRouter } from "vue-router";
import { storeToRefs } from "pinia";
const dialog = useDialogStore(); const dialog = useDialogStore();
dialog.openedFile = dialog.content.files[0]; const { openedFile, comments } = storeToRefs(useDialogStore());
const file = dialog.openedFile; openedFile.value = dialog.content.files[0];
const router = useRouter(); const router = useRouter();
const route = useRoute(); const route = useRoute();
@ -69,15 +70,12 @@ watch(isCommentsOpen, (newVal) => {
} }
}); });
watch( watch(openedFile, (newVal) => {
() => file, removeCommentBubbles();
(newVal) => { if (newVal.comments) {
removeCommentBubbles(); setCommentBubbles();
if (newVal.comments) {
setCommentBubbles();
}
} }
); });
// Functions // Functions
const onPdfLoaded = () => { const onPdfLoaded = () => {
@ -121,8 +119,8 @@ const onPdfLoaded = () => {
}; };
function setCommentBubbles() { function setCommentBubbles() {
if (!file.comments) return; if (!comments.value) return;
file.comments.forEach((comment) => { comments.value.forEach((comment) => {
const bubble = document.createElement("a"); const bubble = document.createElement("a");
bubble.classList.add("comment-bubble"); bubble.classList.add("comment-bubble");