read notification working
This commit is contained in:
parent
0b472988a2
commit
2071d9bd6d
4 changed files with 57 additions and 48 deletions
|
|
@ -7,34 +7,44 @@ export const useUserStore = defineStore("user", () => {
|
|||
|
||||
const { projects } = storeToRefs(useProjectsStore());
|
||||
|
||||
const notifications = computed(() => {
|
||||
return projects.value.reduce((acc, project) => {
|
||||
if (!project.notifications) return acc;
|
||||
const notifications = computed(
|
||||
() => {
|
||||
return projects.value.reduce((acc, project) => {
|
||||
if (!project.notifications) return acc;
|
||||
|
||||
const projectNotifications = project.notifications.map((notification) => {
|
||||
const newNotification = {
|
||||
...notification,
|
||||
project: project,
|
||||
isRead: notification.readby?.includes(user.value.uuid),
|
||||
};
|
||||
const projectNotifications = project.notifications.map(
|
||||
(notification) => {
|
||||
const newNotification = {
|
||||
...notification,
|
||||
project: project,
|
||||
isRead: notification.readby?.includes(user.value.uuid),
|
||||
};
|
||||
|
||||
return newNotification;
|
||||
});
|
||||
return newNotification;
|
||||
}
|
||||
);
|
||||
|
||||
const userNotifications = projectNotifications.filter(
|
||||
(notification) => notification.author.uuid !== user.value.uuid
|
||||
);
|
||||
const userNotifications = projectNotifications.filter(
|
||||
(notification) => notification.author.uuid !== user.value.uuid
|
||||
);
|
||||
|
||||
return [...acc, ...userNotifications];
|
||||
}, []);
|
||||
});
|
||||
return [...acc, ...userNotifications];
|
||||
}, []);
|
||||
},
|
||||
{ deep: true }
|
||||
);
|
||||
|
||||
function readNotification(notificationId) {
|
||||
notifications.value = notifications.value.map((notification) => {
|
||||
if (notification.id === notificationId) {
|
||||
notification.isRead = true;
|
||||
function readNotification(notificationId, projectSlug) {
|
||||
projects.value = projects.value.map((project) => {
|
||||
if (project.slug === projectSlug) {
|
||||
project.notifications = project.notifications.map((notification) => {
|
||||
if (notification.id === notificationId) {
|
||||
notification.readby.push(user.value.uuid);
|
||||
}
|
||||
return notification;
|
||||
});
|
||||
}
|
||||
return notification;
|
||||
return project;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue