Bluesky app fork with some witchin' additions 💫

dedupe trending topics (#9870)

authored by

Spence Pope and committed by
GitHub
9cdfb40c c83dddce

+29 -15
+29 -15
src/state/queries/trending/useTrendingTopics.ts
··· 15 15 16 16 export const DEFAULT_LIMIT = 14 17 17 18 + function dedup(topics: TrendingTopic[]): TrendingTopic[] { 19 + const seen = new Set<string>() 20 + return topics.filter(t => { 21 + if (seen.has(t.link)) return false 22 + seen.add(t.link) 23 + return true 24 + }) 25 + } 26 + 18 27 export const trendingTopicsQueryKey = ['trending-topics'] 19 28 20 29 export function useTrendingTopics() { 21 30 const agent = useAgent() 22 31 const {data: preferences} = usePreferencesQuery() 23 - const mutedWords = React.useMemo(() => { 24 - return preferences?.moderationPrefs?.mutedWords || [] 25 - }, [preferences?.moderationPrefs]) 32 + const mutedWords = React.useMemo( 33 + () => preferences?.moderationPrefs?.mutedWords ?? [], 34 + [preferences?.moderationPrefs?.mutedWords], 35 + ) 26 36 27 37 return useQuery<Response>({ 28 38 refetchOnWindowFocus: true, ··· 40 50 select: React.useCallback( 41 51 (data: Response) => { 42 52 return { 43 - topics: data.topics.filter(t => { 44 - return !hasMutedWord({ 45 - mutedWords, 46 - text: t.topic + ' ' + t.displayName + ' ' + t.description, 47 - }) 48 - }), 49 - suggested: data.suggested.filter(t => { 50 - return !hasMutedWord({ 51 - mutedWords, 52 - text: t.topic + ' ' + t.displayName + ' ' + t.description, 53 - }) 54 - }), 53 + topics: dedup( 54 + data.topics.filter(t => { 55 + return !hasMutedWord({ 56 + mutedWords, 57 + text: t.topic + ' ' + t.displayName + ' ' + t.description, 58 + }) 59 + }), 60 + ), 61 + suggested: dedup( 62 + data.suggested.filter(t => { 63 + return !hasMutedWord({ 64 + mutedWords, 65 + text: t.topic + ' ' + t.displayName + ' ' + t.description, 66 + }) 67 + }), 68 + ), 55 69 } 56 70 }, 57 71 [mutedWords],