read comment notification working
This commit is contained in:
parent
9222069ef5
commit
246d21f85a
17 changed files with 86 additions and 111 deletions
|
|
@ -1,26 +1,45 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { defineStore, storeToRefs } from "pinia";
|
||||
import { ref, computed } from "vue";
|
||||
import { useProjectsStore } from "./projects";
|
||||
|
||||
export const useUserStore = defineStore("user", () => {
|
||||
const user = ref(null);
|
||||
|
||||
const { projects } = storeToRefs(useProjectsStore());
|
||||
|
||||
const notifications = computed(() => {
|
||||
return typeof user.value.notifications === "array"
|
||||
? user.value.notifications
|
||||
: Object.values(user.value.notifications);
|
||||
return projects.value.reduce((acc, project) => {
|
||||
if (!project.notifications) return acc;
|
||||
|
||||
const projectNotifications = project.notifications.map(
|
||||
(notification) => ({
|
||||
...notification,
|
||||
project: {
|
||||
id: project.id,
|
||||
name: project.title,
|
||||
},
|
||||
isRead:
|
||||
notification.author.uuid === user.value.uuid ||
|
||||
notification.readby?.includes(user.value.uuid),
|
||||
})
|
||||
);
|
||||
|
||||
return [...acc, ...projectNotifications];
|
||||
}, []);
|
||||
});
|
||||
|
||||
function readNotification(notificationId) {
|
||||
user.value.notifications.forEach((notification) => {
|
||||
notifications.value = notifications.value.map((notification) => {
|
||||
if (notification.id === notificationId) {
|
||||
notification.isread = "true";
|
||||
notification.isRead = true;
|
||||
}
|
||||
return notification;
|
||||
});
|
||||
}
|
||||
|
||||
function readAllNotifications(notificationId) {
|
||||
user.value.notifications.forEach((notification) => {
|
||||
notification.isread = true;
|
||||
notification.isRead = true;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue