2024-11-16 11:30:51 +01:00
|
|
|
import { defineStore } from "pinia";
|
2024-12-19 16:03:20 +01:00
|
|
|
import { ref, computed, watch } from "vue";
|
2024-11-27 17:51:49 +01:00
|
|
|
import { useRoute } from "vue-router";
|
2024-11-16 11:30:51 +01:00
|
|
|
|
|
|
|
|
export const useDialogStore = defineStore("dialog", () => {
|
|
|
|
|
const content = ref(null);
|
2024-11-16 12:05:37 +01:00
|
|
|
const openedFile = ref(null);
|
2024-12-19 16:03:20 +01:00
|
|
|
|
2024-11-16 12:05:37 +01:00
|
|
|
const comments = computed(() => {
|
|
|
|
|
return openedFile.value.comments;
|
|
|
|
|
});
|
2024-11-16 11:30:51 +01:00
|
|
|
|
2024-11-16 12:05:37 +01:00
|
|
|
function updateFile(newFile) {
|
2024-11-28 14:45:45 +01:00
|
|
|
openedFile.value = newFile;
|
|
|
|
|
|
|
|
|
|
if (!content.value.files) return;
|
2024-11-16 12:05:37 +01:00
|
|
|
content.value.files = content.value.files.map((file) =>
|
|
|
|
|
file.id === newFile.id ? newFile : file
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-27 17:51:49 +01:00
|
|
|
const route = useRoute();
|
|
|
|
|
const isCommentsOpen = ref(
|
|
|
|
|
route.query.hasOwnProperty("comments") ? true : false
|
|
|
|
|
);
|
|
|
|
|
|
2024-12-19 16:03:20 +01:00
|
|
|
const draftComment = ref({});
|
|
|
|
|
watch(
|
|
|
|
|
draftComment,
|
|
|
|
|
(newVal) => {
|
|
|
|
|
if (draftComment.value.position) showDraftMarker(newVal);
|
|
|
|
|
},
|
|
|
|
|
{ deep: true }
|
|
|
|
|
);
|
|
|
|
|
function showDraftMarker(draftComment) {
|
|
|
|
|
console.log("showDraftMarker");
|
|
|
|
|
const bubble = document.createElement("a");
|
|
|
|
|
|
|
|
|
|
bubble.classList.add("comment-marker");
|
|
|
|
|
bubble.classList.add("comment-marker--draft");
|
|
|
|
|
bubble.style.left = draftComment.position.x + "%";
|
|
|
|
|
bubble.style.top = draftComment.position.y + "%";
|
|
|
|
|
bubble.href = "#comment-" + draftComment.id;
|
|
|
|
|
|
|
|
|
|
const container = document.querySelector(
|
|
|
|
|
`.vpv-page-inner-container[aria-label="page ${draftComment.position.pageIndex}"] .page-inner-container`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
container.appendChild(bubble);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
content,
|
|
|
|
|
openedFile,
|
|
|
|
|
comments,
|
|
|
|
|
draftComment,
|
|
|
|
|
isCommentsOpen,
|
|
|
|
|
updateFile,
|
|
|
|
|
};
|
2024-11-16 11:30:51 +01:00
|
|
|
});
|