From 979c97306b310127f4f91763febcaafd84845c3e Mon Sep 17 00:00:00 2001 From: Ayo Date: Sat, 21 Jan 2023 23:41:46 +0100 Subject: [PATCH] refactor: use single filter logic --- components/conversation/ConversationPaginator.vue | 13 +++---------- components/notification/NotificationPaginator.vue | 13 +++---------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/components/conversation/ConversationPaginator.vue b/components/conversation/ConversationPaginator.vue index 72ed1840..d69d5ea8 100644 --- a/components/conversation/ConversationPaginator.vue +++ b/components/conversation/ConversationPaginator.vue @@ -6,16 +6,9 @@ const { paginator } = defineProps<{ }>() function preprocess(items: mastodon.v1.Conversation[]) { - const filteredIndices = items.map( - (items, index) => ( - { - status: items.lastStatus, - index, - })) - .filter(item => !!item.status?.filtered?.find(filter => filter.filter.filterAction === 'hide' && filter.filter.context.includes('thread'))) - .map(item => item.index) - - return items.filter((_, index) => !filteredIndices.includes(index)) + return items.filter(items => !items.lastStatus?.filtered?.find( + filter => filter.filter.filterAction === 'hide' && filter.filter.context.includes('thread'), + )) } diff --git a/components/notification/NotificationPaginator.vue b/components/notification/NotificationPaginator.vue index dc9e96dc..db5e6015 100644 --- a/components/notification/NotificationPaginator.vue +++ b/components/notification/NotificationPaginator.vue @@ -113,16 +113,9 @@ function groupItems(items: mastodon.v1.Notification[]): NotificationSlot[] { } function removeFiltered(items: mastodon.v1.Notification[]): mastodon.v1.Notification[] { - const filteredIndices = items.map( - (items, index) => ( - { - status: items.status, - index, - })) - .filter(item => !!item.status?.filtered?.find(filter => filter.filter.filterAction === 'hide' && filter.filter.context.includes('notifications'))) - .map(item => item.index) - - return items.filter((_, index) => !filteredIndices.includes(index)) + return items.filter(item => !item.status?.filtered?.find( + filter => filter.filter.filterAction === 'hide' && filter.filter.context.includes('notifications'), + )) } function preprocess(items: NotificationSlot[]): NotificationSlot[] {