From b5ea4b74b2adf2f046705f9971ff12b60ee22bf2 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Fri, 27 Dec 2024 14:23:01 -0600 Subject: [PATCH 1/3] Fix mute words in trending --- src/state/queries/trending/useTrendingTopics.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/state/queries/trending/useTrendingTopics.ts b/src/state/queries/trending/useTrendingTopics.ts index 6d3580a8fa..aeb42b3f04 100644 --- a/src/state/queries/trending/useTrendingTopics.ts +++ b/src/state/queries/trending/useTrendingTopics.ts @@ -28,16 +28,17 @@ export function useTrendingTopics() { const {data} = await agent.api.app.bsky.unspecced.getTrendingTopics({ limit: DEFAULT_LIMIT, }) - - const {topics, suggested} = data + return data + }, + select(data) { return { - topics: topics.filter(t => { + topics: data.topics.filter(t => { return !hasMutedWord({ mutedWords, text: t.topic + ' ' + t.displayName + ' ' + t.description, }) }), - suggested: suggested.filter(t => { + suggested: data.suggested.filter(t => { return !hasMutedWord({ mutedWords, text: t.topic + ' ' + t.displayName + ' ' + t.description, From b2afa1ec7ad89153678d886ca88f9f1c5cc0ef96 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Fri, 27 Dec 2024 14:25:14 -0600 Subject: [PATCH 2/3] Defense --- src/state/queries/trending/useTrendingTopics.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/state/queries/trending/useTrendingTopics.ts b/src/state/queries/trending/useTrendingTopics.ts index aeb42b3f04..de57be8322 100644 --- a/src/state/queries/trending/useTrendingTopics.ts +++ b/src/state/queries/trending/useTrendingTopics.ts @@ -28,7 +28,10 @@ export function useTrendingTopics() { const {data} = await agent.api.app.bsky.unspecced.getTrendingTopics({ limit: DEFAULT_LIMIT, }) - return data + return { + topics: data.topics ?? [], + suggested: data.suggested ?? [], + } }, select(data) { return { From ef549156cd54c094ff04da054638690198f41bfa Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Fri, 27 Dec 2024 15:11:23 -0600 Subject: [PATCH 3/3] Actually, memo should work here --- .../queries/trending/useTrendingTopics.ts | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/state/queries/trending/useTrendingTopics.ts b/src/state/queries/trending/useTrendingTopics.ts index de57be8322..757e6a6f7e 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, @@ -33,21 +38,24 @@ export function useTrendingTopics() { suggested: data.suggested ?? [], } }, - select(data) { - 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, - }) - }), - } - }, + 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], + ), }) }