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