Fix mute words in trending (#7293)
This commit is contained in:
@@ -9,6 +9,11 @@ import {useAgent} from '#/state/session'
|
|||||||
|
|
||||||
export type TrendingTopic = AppBskyUnspeccedDefs.TrendingTopic
|
export type TrendingTopic = AppBskyUnspeccedDefs.TrendingTopic
|
||||||
|
|
||||||
|
type Response = {
|
||||||
|
topics: TrendingTopic[]
|
||||||
|
suggested: TrendingTopic[]
|
||||||
|
}
|
||||||
|
|
||||||
export const DEFAULT_LIMIT = 14
|
export const DEFAULT_LIMIT = 14
|
||||||
|
|
||||||
export const trendingTopicsQueryKey = ['trending-topics']
|
export const trendingTopicsQueryKey = ['trending-topics']
|
||||||
@@ -20,7 +25,7 @@ export function useTrendingTopics() {
|
|||||||
return preferences?.moderationPrefs?.mutedWords || []
|
return preferences?.moderationPrefs?.mutedWords || []
|
||||||
}, [preferences?.moderationPrefs])
|
}, [preferences?.moderationPrefs])
|
||||||
|
|
||||||
return useQuery({
|
return useQuery<Response>({
|
||||||
refetchOnWindowFocus: true,
|
refetchOnWindowFocus: true,
|
||||||
staleTime: STALE.MINUTES.THREE,
|
staleTime: STALE.MINUTES.THREE,
|
||||||
queryKey: trendingTopicsQueryKey,
|
queryKey: trendingTopicsQueryKey,
|
||||||
@@ -28,22 +33,29 @@ export function useTrendingTopics() {
|
|||||||
const {data} = await agent.api.app.bsky.unspecced.getTrendingTopics({
|
const {data} = await agent.api.app.bsky.unspecced.getTrendingTopics({
|
||||||
limit: DEFAULT_LIMIT,
|
limit: DEFAULT_LIMIT,
|
||||||
})
|
})
|
||||||
|
|
||||||
const {topics, suggested} = data
|
|
||||||
return {
|
return {
|
||||||
topics: topics.filter(t => {
|
topics: data.topics ?? [],
|
||||||
return !hasMutedWord({
|
suggested: data.suggested ?? [],
|
||||||
mutedWords,
|
|
||||||
text: t.topic + ' ' + t.displayName + ' ' + t.description,
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
suggested: 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],
|
||||||
|
),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user