comments working

This commit is contained in:
isUnknown 2025-01-15 14:18:48 +01:00
parent 375bed1d01
commit 0b472988a2
14 changed files with 107 additions and 59 deletions

View file

@ -85,6 +85,7 @@ import { useApiStore } from "../../stores/api";
import { useDialogStore } from "../../stores/dialog";
import { computed, onMounted, ref, useTemplateRef } from "vue";
import { storeToRefs } from "pinia";
import { usePageStore } from "../../stores/page";
dayjs.locale("fr");
@ -102,6 +103,7 @@ const { activeTracks, openedComment } = storeToRefs(useDialogStore());
const draftText = ref(comment.text);
const editField = ref(null);
const commentNode = useTemplateRef("comment-node");
const { page } = storeToRefs(usePageStore());
let correspondingMarker = null;
// Functions
@ -143,7 +145,7 @@ function handleClick() {
async function read() {
if (getStatus.value !== "unread") return;
try {
const newNotification = await api.readNotification(comment);
const newNotification = await api.readNotification(comment, page.value.uri);
console.log(newNotification);
userStore.readNotification(comment.id);
} catch (error) {

View file

@ -179,7 +179,6 @@ function handleSubmit(event = null) {
}
const date = dayjs().format();
const newComment = {
dialogUri: route.fullPath,
fileName: openedFile.value ? openedFile.value.name : false,
userUuid: user.uuid,
text: draftComment.value.text,
@ -202,7 +201,7 @@ function handleSubmit(event = null) {
async function replyComment(newComment) {
newComment.parentId = openedComment.value.id;
const matchFileParentUri = openedComment.value.location.file.url.match(
const matchFileParentUri = openedFile.value.url.match(
/projects\/.*?(?=\/[^/]+\/[^/]+$)/
);
newComment.fileParentUri = matchFileParentUri ? matchFileParentUri[0] : null;
@ -224,14 +223,16 @@ async function addComment(newComment) {
resetDraftComment();
isAddOpen.value = false;
dialog.updateFile(newFile);
activeTracks.value = activeTracks.value.map((track) => {
if (track.files) {
track.files = track.files.map((file) =>
file.uuid === newFile.uuid ? newFile : file
);
}
return track;
});
if (activeTracks.value) {
activeTracks.value = activeTracks.value.map((track) => {
if (track.files) {
track.files = track.files.map((file) =>
file.uuid === newFile.uuid ? newFile : file
);
}
return track;
});
}
}
function resetDraftComment() {
@ -318,11 +319,15 @@ function openComment(comment) {
openedComment.value = comment;
if (activeTracks.value?.length === 1) {
openedFile.value = activeTracks.value[0].files.find(
(file) => file.uuid === openedComment.value.location.file.uuid
);
showCorrespondingView();
}
}
function showCorrespondingView() {
openedFile.value = activeTracks.value[0].files.find(
(file) => file.uuid === openedComment.value.location.file.uuid
);
}
</script>
<style>

View file

@ -2,7 +2,7 @@
<article
class="notification | bg-white rounded-lg | p-16 | flow"
data-type="comment"
@click="router.push(targetUri + '&comments=true')"
@click="router.push(href)"
>
<header>
<p class="flex">
@ -12,8 +12,10 @@
>Commentaire</strong
>
<span class="notification__client | text-grey-700"
>{{ project.title }}
{{ project?.status === "unlisted" ? "(archivé)" : "" }}</span
>{{ notification.project.title }}
{{
notification.project?.status === "unlisted" ? "(archivé)" : ""
}}</span
>
<time
datetime=""
@ -39,16 +41,29 @@
<script setup>
import { useRouter } from "vue-router";
import { useNotificationsStore } from "../../stores/notifications";
import { useProjectsStore } from "../../stores/projects";
const router = useRouter();
const { notification } = defineProps({ notification: Object });
const { formatDate } = useNotificationsStore();
const { getProjectByUuid } = useProjectsStore();
const project = getProjectByUuid(notification.location.project.uuid);
const targetUri = notification.location.dialoguri.replace(
/\/projects\/([a-z0-9\-]+)/,
"/projects/" + notification.target.slug
);
const href = getTargetPath();
// Functions
function getTargetPath() {
const uri = notification.location.page.uri;
const isDocumentBrief =
notification.location.page.template === "client-brief" &&
notification.location?.file.type === "document";
if (isDocumentBrief) {
return notification.project.uri + "?dialog=client-brief&comments=true";
}
if (notification.location.page.template === "track") {
return notification.project.uri + "?dialog=virtual-sample&comments=true";
}
return uri;
}
</script>