From 8b7a33181534b4bce1a74ba81e20db8195f1ae40 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Fri, 27 Dec 2024 16:19:02 -0600 Subject: Fix mute words in trending (#7293) --- src/state/queries/trending/useTrendingTopics.ts | 42 ++++++++++++++++--------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/state/queries/trending/useTrendingTopics.ts b/src/state/queries/trending/useTrendingTopics.ts index 6d3580a8f..757e6a6f7 100644 --- a/src/state/queries/trending/useTrendingTopics.ts +++ b/src/state/queries/trending/useTrendingTopics.ts @@ -9,6 +9,11 @@ import {useAgent} from '#/state/session' export type TrendingTopic = AppBskyUnspeccedDefs.TrendingTopic +type Response = { + topics: TrendingTopic[] + suggested: TrendingTopic[] +} + export const DEFAULT_LIMIT = 14 export const trendingTopicsQueryKey = ['trending-topics'] @@ -20,7 +25,7 @@ export function useTrendingTopics() { return preferences?.moderationPrefs?.mutedWords || [] }, [preferences?.moderationPrefs]) - return useQuery({ + return useQuery({ refetchOnWindowFocus: true, staleTime: STALE.MINUTES.THREE, queryKey: trendingTopicsQueryKey, @@ -28,22 +33,29 @@ export function useTrendingTopics() { const {data} = await agent.api.app.bsky.unspecced.getTrendingTopics({ limit: DEFAULT_LIMIT, }) - - const {topics, suggested} = data return { - topics: topics.filter(t => { - return !hasMutedWord({ - mutedWords, - text: t.topic + ' ' + t.displayName + ' ' + t.description, - }) - }), - suggested: suggested.filter(t => { - return !hasMutedWord({ - mutedWords, - text: t.topic + ' ' + t.displayName + ' ' + t.description, - }) - }), + topics: data.topics ?? [], + suggested: data.suggested ?? [], } }, + select: React.useCallback( + (data: Response) => { + return { + topics: data.topics.filter(t => { + return !hasMutedWord({ + mutedWords, + text: t.topic + ' ' + t.displayName + ' ' + t.description, + }) + }), + suggested: data.suggested.filter(t => { + return !hasMutedWord({ + mutedWords, + text: t.topic + ' ' + t.displayName + ' ' + t.description, + }) + }), + } + }, + [mutedWords], + ), }) } -- cgit 1.4.1