From f968c12ccfa2c9c0b530e92fb62289da5b3d9f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Thu, 19 Sep 2019 15:33:35 +0200 Subject: [PATCH] Implement updating by time and add new ones to the list --- .../NotificationMenu/NotificationMenu.vue | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/webapp/components/notifications/NotificationMenu/NotificationMenu.vue b/webapp/components/notifications/NotificationMenu/NotificationMenu.vue index 51b90089f..af52d8395 100644 --- a/webapp/components/notifications/NotificationMenu/NotificationMenu.vue +++ b/webapp/components/notifications/NotificationMenu/NotificationMenu.vue @@ -35,7 +35,39 @@ export default { props: { placement: { type: String }, }, + created() { + setInterval(this.updateNotifications, 10000) + }, + destroyed() { + clearInterval(this.updateNotifications) + }, methods: { + async updateNotifications() { + try { + const { + data: { notifications }, + } = await this.$apollo.mutate({ + mutation: notificationQuery(this.$i18n), + }) + // add all the new notifications to the notifications + if (notifications) { + notifications.forEach(updatedElement => { + const sameNotification = this.notifications.find(function(oldElement) { + return ( + oldElement.from.id === updatedElement.from.id && + oldElement.createdAt === updatedElement.createdAt && + oldElement.reason === updatedElement.reason + ) + }) + if (sameNotification === undefined) { + this.notifications.unshift(updatedElement) + } + }) + } + } catch (err) { + throw new Error(err) + } + }, async markAsRead(notificationSourceId) { const variables = { id: notificationSourceId } try {