From 8eaa893994fe228b0261e4fe52301bdbfe55e5b2 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Thu, 2 Oct 2025 15:12:20 +0200 Subject: [PATCH] #170 --- src/components/comments/Comments.vue | 53 ++++++--- .../project/virtual-sample/DynamicView.vue | 112 ++++++++++-------- src/stores/user.js | 2 +- src/stores/virtualSample.js | 8 +- 4 files changed, 104 insertions(+), 71 deletions(-) diff --git a/src/components/comments/Comments.vue b/src/components/comments/Comments.vue index 02c3912..f1da3b6 100644 --- a/src/components/comments/Comments.vue +++ b/src/components/comments/Comments.vue @@ -114,7 +114,7 @@ import dayjs from 'dayjs'; import 'dayjs/locale/fr'; import uniqid from 'uniqid'; -import { watch, ref, computed } from 'vue'; +import { watch, ref, computed, onBeforeUnmount } from 'vue'; import { useUserStore } from '../../stores/user'; import { usePageStore } from '../../stores/page'; import { useApiStore } from '../../stores/api'; @@ -158,10 +158,12 @@ watch(isAddOpen, (newVal) => { } }); -const viewContainer = - openedFile.value?.type === 'document' +const viewContainer = computed(() => { + if (!openedFile.value) return null; + return openedFile.value.type === 'document' ? document.querySelector('.vpv-pages-inner-container') : document.querySelector('.track'); +}); window.addEventListener('keydown', (event) => { if ( @@ -256,20 +258,8 @@ function closeComment() { openedComment.value = null; } -function toggleCommentPositionMode(enable) { - if (enable) { - waitingForCommentPosition.value = true; - viewContainer.classList.add('waiting-comment'); - viewContainer.addEventListener('click', handleCommentPositionClick); - } else { - waitingForCommentPosition.value = false; - viewContainer.classList.remove('waiting-comment'); - viewContainer.removeEventListener('click', handleCommentPositionClick); - } -} - function handleCommentPositionClick(event) { - if (openedFile.value.type === 'document') { + if (openedFile.value?.type === 'document') { prepareDraftCommentInPdf(event); } else { prepareDraftCommentInImage(event); @@ -278,6 +268,21 @@ function handleCommentPositionClick(event) { toggleCommentPositionMode(false); } +function toggleCommentPositionMode(enable) { + const container = viewContainer.value; + if (!container) return; // sécurité + + if (enable) { + waitingForCommentPosition.value = true; + container.classList.add('waiting-comment'); + container.addEventListener('click', handleCommentPositionClick); + } else { + waitingForCommentPosition.value = false; + container.classList.remove('waiting-comment'); + container.removeEventListener('click', handleCommentPositionClick); + } +} + function prepareDraftCommentInPdf(event) { const pageContainer = event.target.closest('.page-inner-container'); if (!pageContainer || !viewContainer) return; @@ -287,7 +292,10 @@ function prepareDraftCommentInPdf(event) { .getAttribute('aria-label'); const pageIndex = pageLabel.charAt(pageLabel.length - 1); - const viewRect = viewContainer.getBoundingClientRect(); + const container = viewContainer.value; + if (!container) return; + const viewRect = container.getBoundingClientRect(); + const pageRect = pageContainer.getBoundingClientRect(); const pageScroll = viewRect.top - pageRect.top; @@ -310,7 +318,9 @@ function prepareDraftCommentInPdf(event) { function prepareDraftCommentInImage(event) { if (!viewContainer) return; - const imageRect = viewContainer.getBoundingClientRect(); + const container = viewContainer.value; + if (!container) return; // sécurité + const imageRect = container.getBoundingClientRect(); const mouseTop = event.clientY; const mouseLeft = event.clientX; @@ -339,4 +349,11 @@ function showCorrespondingView() { (file) => file.uuid === openedComment.value.location.file.uuid ); } + +onBeforeUnmount(() => { + const container = viewContainer.value; + if (container) { + container.removeEventListener('click', handleCommentPositionClick); + } +}); diff --git a/src/components/project/virtual-sample/DynamicView.vue b/src/components/project/virtual-sample/DynamicView.vue index f792c5a..f89552b 100644 --- a/src/components/project/virtual-sample/DynamicView.vue +++ b/src/components/project/virtual-sample/DynamicView.vue @@ -9,9 +9,9 @@ :items="track.variations" :isCompareModeEnabled="isCompareModeEnabled" :index="index" - @update:selectedItems="selectTrack" /> +