Skip to content

Commit

Permalink
Fix mute words in trending (#7293)
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey authored Dec 27, 2024
1 parent d27ed32 commit 8b7a331
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/state/queries/trending/useTrendingTopics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -20,30 +25,37 @@ export function useTrendingTopics() {
return preferences?.moderationPrefs?.mutedWords || []
}, [preferences?.moderationPrefs])

return useQuery({
return useQuery<Response>({
refetchOnWindowFocus: true,
staleTime: STALE.MINUTES.THREE,
queryKey: trendingTopicsQueryKey,
async queryFn() {
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],
),
})
}

0 comments on commit 8b7a331

Please sign in to comment.