From 8d200b8a99229a01b7f6a3a0aa4bcfa23beb7ae9 Mon Sep 17 00:00:00 2001 From: iamsivin Date: Tue, 13 Feb 2024 08:54:56 +0530 Subject: [PATCH] chore: Review fix --- .../routes/dashboard/inbox/InboxView.vue | 19 +++++++++---------- .../store/modules/notifications/getters.js | 3 +++ .../specs/notifications/getters.spec.js | 10 ++++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/javascript/dashboard/routes/dashboard/inbox/InboxView.vue b/app/javascript/dashboard/routes/dashboard/inbox/InboxView.vue index bf690be5b..a224d1cc1 100644 --- a/app/javascript/dashboard/routes/dashboard/inbox/InboxView.vue +++ b/app/javascript/dashboard/routes/dashboard/inbox/InboxView.vue @@ -12,7 +12,7 @@ > n.id === Number(this.notificationId)); + return this.activeNotificationById(this.notificationId); }, conversationId() { - return this.activeNotification?.primary_actor.id; + return this.activeNotification?.primary_actor?.id; }, isInboxViewEnabled() { return this.$store.getters['accounts/isFeatureEnabledGlobally']( @@ -111,7 +112,7 @@ export default { totalNotifications() { return this.notifications?.length ?? 0; }, - activeNotificationIndex() { + activeNotificationPosition() { const notificationIndex = this.notifications.findIndex( n => n.id === Number(this.notificationId) ); @@ -178,9 +179,7 @@ export default { }); }, findConversation() { - return this.allConversation.find( - c => c.id === Number(this.conversationId) - ); + return this.conversationById(this.conversationId); }, navigateToConversation(activeIndex, direction) { const indexOffset = direction === 'next' ? 0 : -2; @@ -212,10 +211,10 @@ export default { } }, onClickNext() { - this.navigateToConversation(this.activeNotificationIndex, 'next'); + this.navigateToConversation(this.activeNotificationPosition, 'next'); }, onClickPrev() { - this.navigateToConversation(this.activeNotificationIndex, 'prev'); + this.navigateToConversation(this.activeNotificationPosition, 'prev'); }, onToggleContactPanel() { this.updateUISettings({ diff --git a/app/javascript/dashboard/store/modules/notifications/getters.js b/app/javascript/dashboard/store/modules/notifications/getters.js index b8df2b173..ece9e228d 100644 --- a/app/javascript/dashboard/store/modules/notifications/getters.js +++ b/app/javascript/dashboard/store/modules/notifications/getters.js @@ -14,6 +14,9 @@ export const getters = { ); return sortedNotifications; }, + getActiveNotificationById: $state => id => { + return $state.records[id] || {}; + }, getUIFlags($state) { return $state.uiFlags; }, diff --git a/app/javascript/dashboard/store/modules/specs/notifications/getters.spec.js b/app/javascript/dashboard/store/modules/specs/notifications/getters.spec.js index d557fca7a..5418f5b66 100644 --- a/app/javascript/dashboard/store/modules/specs/notifications/getters.spec.js +++ b/app/javascript/dashboard/store/modules/specs/notifications/getters.spec.js @@ -42,6 +42,16 @@ describe('#getters', () => { ]); }); + it('getActiveNotificationById', () => { + const state = { + records: { + 1: { id: 1 }, + }, + }; + expect(getters.getActiveNotificationById(state)(1)).toEqual({ id: 1 }); + expect(getters.getActiveNotificationById(state)(2)).toEqual({}); + }); + it('getUIFlags', () => { const state = { uiFlags: {