mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at rm-broken-strings 60 lines 1.8 kB view raw
1import {AppBskyFeedGetActorFeeds, moderateFeedGenerator} from '@atproto/api' 2import {InfiniteData, QueryKey, useInfiniteQuery} from '@tanstack/react-query' 3 4import {useAgent} from '#/state/session' 5import {useModerationOpts} from '../preferences/moderation-opts' 6 7const PAGE_SIZE = 50 8type RQPageParam = string | undefined 9 10// TODO refactor invalidate on mutate? 11export const RQKEY_ROOT = 'profile-feedgens' 12export const RQKEY = (did: string) => [RQKEY_ROOT, did] 13 14export function useProfileFeedgensQuery( 15 did: string, 16 opts?: {enabled?: boolean}, 17) { 18 const moderationOpts = useModerationOpts() 19 const enabled = opts?.enabled !== false && Boolean(moderationOpts) 20 const agent = useAgent() 21 return useInfiniteQuery< 22 AppBskyFeedGetActorFeeds.OutputSchema, 23 Error, 24 InfiniteData<AppBskyFeedGetActorFeeds.OutputSchema>, 25 QueryKey, 26 RQPageParam 27 >({ 28 queryKey: RQKEY(did), 29 async queryFn({pageParam}: {pageParam: RQPageParam}) { 30 const res = await agent.app.bsky.feed.getActorFeeds({ 31 actor: did, 32 limit: PAGE_SIZE, 33 cursor: pageParam, 34 }) 35 res.data.feeds.sort((a, b) => { 36 return (b.likeCount || 0) - (a.likeCount || 0) 37 }) 38 return res.data 39 }, 40 initialPageParam: undefined, 41 getNextPageParam: lastPage => lastPage.cursor, 42 enabled, 43 select(data) { 44 return { 45 ...data, 46 pages: data.pages.map(page => { 47 return { 48 ...page, 49 feeds: page.feeds 50 // filter by labels 51 .filter(list => { 52 const decision = moderateFeedGenerator(list, moderationOpts!) 53 return !decision.ui('contentList').filter 54 }), 55 } 56 }), 57 } 58 }, 59 }) 60}