Skip to content

Commit

Permalink
fix: improve notifications management
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKolarik committed Oct 23, 2024
1 parent 1e246c3 commit 237bcf2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
</div>
<Popover ref="notificationsPanel">
<Accordion v-if="reverseNotifications.length" class="box-border w-96 max-w-[calc(100vw-16px)]" expand-icon="pi pi-chevron-right">
<AccordionPanel v-for="notification in reverseNotifications" :key="notification.id" :value="notification.id">
<AccordionHeader>{{ notification.subject }}</AccordionHeader>
<AccordionPanel v-for="notification in reverseNotifications" :key="notification.id" :value="notification.id" @click="markNotificationAsRead(notification.id)">
<AccordionHeader :class="{ '!font-normal': notification.status !== 'inbox' }">{{ notification.subject }}</AccordionHeader>
<AccordionContent>
<!-- eslint-disable-next-line vue/no-v-html -->
<span v-if="notification.message" class="notification" v-html="notification.message"/>
Expand Down Expand Up @@ -132,10 +132,16 @@
const notificationsPanel = ref();
const toggleNotifications = async (event: Event) => {
notificationsPanel.value.toggle(event);
};
const markNotificationAsRead = async (id: string) => {
const notification = notifications.value.find(notification => notification.id === id);
if (newNotifications.value.length) {
await $directus.request(updateNotifications(newNotifications.value.map(notification => notification.id), { status: 'archived' }));
if (!notification) {
return;
}
notification.status = 'archived';
await $directus.request(updateNotifications([ notification.id ], { status: notification.status }));
};
const { data: notifications } = await useAsyncData('directus_notifications', async () => {
Expand Down

0 comments on commit 237bcf2

Please sign in to comment.