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

@ -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,
}),
};

View file

@ -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];
}, []);
});