From d831e141095c76c2e0a713875e8d008964b4ac8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adem=C3=ADlson=20F=2E=20Tonato?= Date: Sat, 24 Oct 2020 19:41:03 +0100 Subject: [PATCH] feat: add button to mark all notifications as read on notification page --- webapp/pages/notifications/index.vue | 51 ++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/webapp/pages/notifications/index.vue b/webapp/pages/notifications/index.vue index f59eef2f1..0c404dc04 100644 --- a/webapp/pages/notifications/index.vue +++ b/webapp/pages/notifications/index.vue @@ -15,7 +15,28 @@ @markNotificationAsRead="markNotificationAsRead" :notifications="notifications" /> - + + + + + {{ $t('notifications.markAllAsRead') }} + + + + + + @@ -23,7 +44,7 @@ import NotificationsTable from '~/components/NotificationsTable/NotificationsTable' import DropdownFilter from '~/components/DropdownFilter/DropdownFilter' import PaginationButtons from '~/components/_new/generic/PaginationButtons/PaginationButtons' -import { notificationQuery, markAsReadMutation } from '~/graphql/User' +import { notificationQuery, markAsReadMutation, markAllAsReadMutation } from '~/graphql/User' export default { components: { @@ -54,6 +75,15 @@ export default { { label: this.$t('notifications.filterLabel.unread'), value: false }, ] }, + hasNotifications() { + return this.notifications.length + }, + unreadNotificationsCount() { + const result = this.notifications.reduce((count, notification) => { + return notification.read ? count : count + 1 + }, 0) + return result + }, }, methods: { filter(option) { @@ -77,6 +107,19 @@ export default { next() { this.offset += this.pageSize }, + async markAllAsRead() { + if (!this.hasNotifications) { + return + } + + try { + await this.$apollo.mutate({ + mutation: markAllAsReadMutation(this.$i18n), + }) + } catch (error) { + this.$toast.error(error.message) + } + }, }, apollo: { notifications: { @@ -112,4 +155,8 @@ export default { .notifications-page-flex { justify-content: space-between; } + +.notifications-footer { + text-align: center; +}