-
Notifications
You must be signed in to change notification settings - Fork 0
/
$actor.lazy.tsx
40 lines (36 loc) · 1.18 KB
/
$actor.lazy.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { AppBskyFeedDefs } from '@atproto/api'
import { createLazyFileRoute } from '@tanstack/react-router'
import { useCallback, useMemo, useState } from 'react'
import { useApi } from '../../ApiProvider/useApi'
import FeedView from '../../Skygram/Feeds/FeedView'
import fetchAuthorFeed from '../../Skygram/Feeds/fetchAuthorFeed'
export const Route = createLazyFileRoute('/posters/$actor')({
component: RouteComponent,
})
function RouteComponent() {
const { actor } = Route.useParams()
const {agent } = useApi()
const [cursor,setCursor] = useState<string|undefined>(undefined)
const queryKey = useMemo<Array<string|object>>(
() => [
'getAuthorFeed',
actor,
{
filter: 'posts_with_media',
limit: 30,
}
],
[actor,]
)
const queryFn = useCallback(() => {
return fetchAuthorFeed({ actor, cursor, agent, }).then(
(data:{cursor?:string,feed:AppBskyFeedDefs.FeedViewPost[]}) => {
if( data.cursor != cursor ) {
setCursor(data.cursor);
}
return data;
}
)
}, [actor, cursor, agent]);
return <FeedView queryFn={queryFn} queryKey={queryKey}/>
}