comments working
This commit is contained in:
parent
375bed1d01
commit
0b472988a2
14 changed files with 107 additions and 59 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -34,6 +34,24 @@ const routes = [
|
|||
path: "/projects/:id/extended-brief",
|
||||
component: Brief,
|
||||
},
|
||||
|
||||
// Redirections
|
||||
{
|
||||
path: "/projects/:id/industrial-ideation",
|
||||
redirect: (to) => {
|
||||
return (
|
||||
"/projects/" +
|
||||
to.params.id +
|
||||
"?dialog=industrial-ideation&comments=true"
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/projects/:id/proposal",
|
||||
redirect: (to) => {
|
||||
return "/projects/" + to.params.id + "?dialog=proposal&comments=true";
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { defineStore, storeToRefs } from "pinia";
|
||||
import { usePageStore } from "./page.js";
|
||||
import uniqid from "uniqid";
|
||||
|
||||
export const useApiStore = defineStore("api", () => {
|
||||
|
|
@ -142,11 +143,17 @@ export const useApiStore = defineStore("api", () => {
|
|||
}
|
||||
}
|
||||
|
||||
async function readNotification(comment) {
|
||||
/**
|
||||
*
|
||||
* @param {string} comment
|
||||
* @param {string} projectId UUID or URI
|
||||
* @returns status with message if error
|
||||
*/
|
||||
async function readNotification(comment, projectId) {
|
||||
const headers = {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
projectUuid: comment.location.project.uuid,
|
||||
projectId,
|
||||
notificationId: comment.id,
|
||||
}),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,21 +11,21 @@ export const useUserStore = defineStore("user", () => {
|
|||
return projects.value.reduce((acc, project) => {
|
||||
if (!project.notifications) return acc;
|
||||
|
||||
const projectNotifications = project.notifications.map(
|
||||
(notification) => ({
|
||||
const projectNotifications = project.notifications.map((notification) => {
|
||||
const newNotification = {
|
||||
...notification,
|
||||
target: {
|
||||
uuid: project.uuid,
|
||||
title: project.title,
|
||||
slug: project.slug,
|
||||
},
|
||||
isRead:
|
||||
notification.author.uuid === user.value.uuid ||
|
||||
notification.readby?.includes(user.value.uuid),
|
||||
})
|
||||
project: project,
|
||||
isRead: notification.readby?.includes(user.value.uuid),
|
||||
};
|
||||
|
||||
return newNotification;
|
||||
});
|
||||
|
||||
const userNotifications = projectNotifications.filter(
|
||||
(notification) => notification.author.uuid !== user.value.uuid
|
||||
);
|
||||
|
||||
return [...acc, ...projectNotifications];
|
||||
return [...acc, ...userNotifications];
|
||||
}, []);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue