From b79770469fd7773d5c9816ab5a4325cd6010ebfa Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Tue, 22 Oct 2019 14:40:10 +0200 Subject: [PATCH] Update notifications page - display more notifications by simplifying the table - get sorting working --- .../Notification/Notification.spec.js | 0 .../Notification/Notification.vue | 0 .../NotificationList/NotificationList.spec.js | 0 .../NotificationList/NotificationList.vue | 0 .../NotificationMenu/NotificationMenu.spec.js | 0 .../NotificationMenu/NotificationMenu.vue | 20 ++- webapp/graphql/User.js | 4 +- webapp/locales/en.json | 2 +- webapp/pages/notifications/index.vue | 135 +++++++----------- 9 files changed, 71 insertions(+), 90 deletions(-) rename webapp/components/{notifications => }/Notification/Notification.spec.js (100%) rename webapp/components/{notifications => }/Notification/Notification.vue (100%) rename webapp/components/{notifications => }/NotificationList/NotificationList.spec.js (100%) rename webapp/components/{notifications => }/NotificationList/NotificationList.vue (100%) rename webapp/components/{notifications => }/NotificationMenu/NotificationMenu.spec.js (100%) rename webapp/components/{notifications => }/NotificationMenu/NotificationMenu.vue (87%) diff --git a/webapp/components/notifications/Notification/Notification.spec.js b/webapp/components/Notification/Notification.spec.js similarity index 100% rename from webapp/components/notifications/Notification/Notification.spec.js rename to webapp/components/Notification/Notification.spec.js diff --git a/webapp/components/notifications/Notification/Notification.vue b/webapp/components/Notification/Notification.vue similarity index 100% rename from webapp/components/notifications/Notification/Notification.vue rename to webapp/components/Notification/Notification.vue diff --git a/webapp/components/notifications/NotificationList/NotificationList.spec.js b/webapp/components/NotificationList/NotificationList.spec.js similarity index 100% rename from webapp/components/notifications/NotificationList/NotificationList.spec.js rename to webapp/components/NotificationList/NotificationList.spec.js diff --git a/webapp/components/notifications/NotificationList/NotificationList.vue b/webapp/components/NotificationList/NotificationList.vue similarity index 100% rename from webapp/components/notifications/NotificationList/NotificationList.vue rename to webapp/components/NotificationList/NotificationList.vue diff --git a/webapp/components/notifications/NotificationMenu/NotificationMenu.spec.js b/webapp/components/NotificationMenu/NotificationMenu.spec.js similarity index 100% rename from webapp/components/notifications/NotificationMenu/NotificationMenu.spec.js rename to webapp/components/NotificationMenu/NotificationMenu.spec.js diff --git a/webapp/components/notifications/NotificationMenu/NotificationMenu.vue b/webapp/components/NotificationMenu/NotificationMenu.vue similarity index 87% rename from webapp/components/notifications/NotificationMenu/NotificationMenu.vue rename to webapp/components/NotificationMenu/NotificationMenu.vue index 255101139..4ab3dedca 100644 --- a/webapp/components/notifications/NotificationMenu/NotificationMenu.vue +++ b/webapp/components/NotificationMenu/NotificationMenu.vue @@ -13,7 +13,9 @@ - {{ $t('notifications.page') }} + + {{ $t('notifications.page') }} + @@ -35,6 +37,7 @@ export default { return { displayedNotifications: [], notifications: [], + nofiticationRead: null, } }, props: { @@ -75,15 +78,24 @@ export default { } return countUnread }, + updateNotifications() { + return this.notificationRead + }, }, apollo: { notifications: { query() { return notificationQuery(this.$i18n) }, + variables() { + return { + read: false, + orderBy: 'updatedAt_desc', + } + }, pollInterval: NOTIFICATIONS_POLL_INTERVAL, - update(data) { - const newNotifications = data.notifications.filter(newN => { + update({ notifications }) { + const newNotifications = notifications.filter(newN => { return !this.displayedNotifications.find(oldN => this.equalNotification(newN, oldN)) }) this.displayedNotifications = newNotifications @@ -91,7 +103,7 @@ export default { .sort((a, b) => { return new Date(b.createdAt) - new Date(a.createdAt) }) - return data.notifications + return notifications }, error(error) { this.$toast.error(error.message) diff --git a/webapp/graphql/User.js b/webapp/graphql/User.js index 54d5889e2..5a4b18b6a 100644 --- a/webapp/graphql/User.js +++ b/webapp/graphql/User.js @@ -51,8 +51,8 @@ export const notificationQuery = i18n => { ${commentFragment(lang)} ${postFragment(lang)} - query { - notifications(orderBy: updatedAt_desc) { + query($read: Boolean, $orderBy: NotificationOrdering) { + notifications(read: $read, orderBy: $orderBy) { read reason createdAt diff --git a/webapp/locales/en.json b/webapp/locales/en.json index 59b8a9390..c978a35a7 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -182,7 +182,7 @@ "createdAt": "Notification created at", "type": "Type", "user": "User", - "action": "Action" + "content": "Content" }, "search": { "placeholder": "Search", diff --git a/webapp/pages/notifications/index.vue b/webapp/pages/notifications/index.vue index fcbebd1c2..118ca0d45 100644 --- a/webapp/pages/notifications/index.vue +++ b/webapp/pages/notifications/index.vue @@ -14,7 +14,7 @@ @click.prevent="toggleMenu()" > - {{ 'All' }} + {{ selected }} - {{ item.route.option }} + {{ item.route.label }} @@ -39,51 +39,12 @@ - - + + @@ -136,23 +98,29 @@ export default { }, data() { return { - notifications: [], - sortingOptions: ['All', 'Read', 'Unread'], + selectedNotifications: [], + selected: 'All', + sortingOptions: [ + { label: 'All', value: null }, + { label: 'Read', value: true }, + { label: 'Unread', value: false }, + ], nofiticationRead: null, } }, computed: { fields() { return { - notifications: null, - // user: this.$t('notifications.user'), - // type: this.$t('notifications.type'), + user: this.$t('notifications.user'), + post: this.$t('notifications.type'), + content: this.$t('notifications.content'), } }, routes() { let routes = this.sortingOptions.map(option => { return { - option, + label: option.label, + value: option.value, } }) return routes @@ -160,24 +128,25 @@ export default { }, methods: { sortNotifications(option, toggleMenu) { - if (option === 'Read') { - this.notificationRead = true - } else if (option === 'Unread') { - this.notificationRead = false - } else { - this.notificationRead = null - } - this.$apollo.queries.notificationsPage.refetch() + this.notificationRead = option.value + this.selected = option.label + this.$apollo.queries.notifications.refresh() toggleMenu() }, }, apollo: { - notificationsPage: { + notifications: { query() { return notificationQuery(this.$i18n) }, + variables() { + return { + read: this.notificationRead, + orderBy: 'updatedAt_desc', + } + }, update({ notifications }) { - this.notifications = notifications + this.selectedNotifications = notifications }, fetchPolicy: 'cache-and-network', error(error) { @@ -191,7 +160,7 @@ export default { .sorting-dropdown { float: right; } -#notifications-table thead { - display: none; +.notifications-table td { + width: 500px; }