diff options
author | Eric Bailey <git@esb.lol> | 2024-12-27 16:19:02 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-27 14:19:02 -0800 |
commit | 8b7a33181534b4bce1a74ba81e20db8195f1ae40 (patch) | |
tree | 24d21f97be72937e37bbef527ef4e09aab9ac635 /src | |
parent | d27ed321887f46c87ca4a511f9ab6703d006db36 (diff) | |
download | voidsky-8b7a33181534b4bce1a74ba81e20db8195f1ae40.tar.zst |
Fix mute words in trending (#7293)
Diffstat (limited to 'src')
-rw-r--r-- | src/state/queries/trending/useTrendingTopics.ts | 42 |
1 files changed, 27 insertions, 15 deletions
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<Response>({ 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], + ), }) } |