@@ -24,93 +24,136 @@ export const Route = createFileRoute('/profile/$handle/')({
24
24
function All ( ) {
25
25
const { t } = useTranslation ( 'app' ) ;
26
26
const { handle } = Route . useParams ( ) ;
27
- const { data : feed , isLoading } = useAuthorFeed ( { handle } ) ;
27
+ const { data, isLoading, fetchNextPage } = useAuthorFeed ( { handle } ) ;
28
+ const feed = data ?. pages . flatMap ( ( page ) => page . feed ) ;
28
29
29
30
if ( isLoading ) return t ( 'loading' ) ;
31
+ if ( ! feed ) return null ;
30
32
31
33
return (
32
- < div className = "flex flex-col gap-2" > { feed ?. map ( ( { post } ) => < PostCard key = { post . uri } post = { post as BSkyPost } /> ) } </ div >
34
+ < Virtuoso
35
+ useWindowScroll
36
+ totalCount = { feed . length }
37
+ endReached = { ( ) => fetchNextPage ( ) }
38
+ components = { {
39
+ List : forwardRef ( ( props , ref ) => < div ref = { ref } { ...props } className = "flex flex-col gap-2" /> ) ,
40
+ } }
41
+ itemContent = { ( index : number ) => < PostCard key = { feed [ index ] ?. post . uri } post = { feed [ index ] ?. post as BSkyPost } /> }
42
+ />
33
43
) ;
34
44
}
35
45
36
46
function Posts ( ) {
37
47
const { t } = useTranslation ( 'app' ) ;
38
48
const { handle } = Route . useParams ( ) ;
39
- const { data : posts , isLoading } = useAuthorFeed ( { handle } ) ;
49
+ const { data, isLoading, fetchNextPage } = useAuthorFeed ( { handle } ) ;
50
+ const feed = data ?. pages . flatMap ( ( page ) => page . feed ) ;
40
51
41
52
if ( isLoading ) return t ( 'loading' ) ;
42
- if ( ! posts ) return null ;
53
+ if ( ! feed ) return null ;
43
54
44
- const filteredPosts = posts
55
+ const filteredPosts = feed
45
56
// Filter out replies
46
57
?. filter ( ( { post } ) => ! ( post . record as BSkyPost [ 'record' ] ) . reply )
47
58
// Filter out reposts of other users
48
59
?. filter ( ( { post } ) => post . author . handle === handle ) ;
49
60
50
61
return (
51
- < div className = "w-[550px]" >
52
- < Virtuoso
53
- useWindowScroll
54
- totalCount = { filteredPosts . length }
55
- components = { {
56
- List : forwardRef ( ( props , ref ) => < div ref = { ref } { ...props } className = "flex flex-col gap-2" /> ) ,
57
- } }
58
- itemContent = { ( index : number ) => (
59
- < PostCard key = { filteredPosts [ index ] ?. post . uri } post = { filteredPosts [ index ] ?. post as BSkyPost } />
60
- ) }
61
- />
62
- </ div >
62
+ < Virtuoso
63
+ useWindowScroll
64
+ totalCount = { feed . length }
65
+ endReached = { ( ) => fetchNextPage ( ) }
66
+ components = { {
67
+ List : forwardRef ( ( props , ref ) => < div ref = { ref } { ...props } className = "flex flex-col gap-2" /> ) ,
68
+ } }
69
+ itemContent = { ( index : number ) => (
70
+ < PostCard key = { filteredPosts [ index ] ?. post . uri } post = { filteredPosts [ index ] ?. post as BSkyPost } />
71
+ ) }
72
+ />
63
73
) ;
64
74
}
65
75
66
76
function Reposts ( ) {
67
77
const { t } = useTranslation ( 'app' ) ;
68
78
const { handle } = Route . useParams ( ) ;
69
- const { data : feed , isLoading } = useAuthorFeed ( { handle } ) ;
79
+ const { data, isLoading, fetchNextPage } = useAuthorFeed ( { handle } ) ;
80
+ const feed = data ?. pages . flatMap ( ( page ) => page . feed ) ;
70
81
71
82
if ( isLoading ) return t ( 'loading' ) ;
83
+ if ( ! feed ) return null ;
84
+
85
+ const filteredPosts = feed
86
+ // Filter only reposts
87
+ ?. filter ( ( { post } ) => post . author . handle !== handle ) ;
72
88
73
89
return (
74
- < div className = "flex flex-col gap-2" >
75
- { feed
76
- // Filter only reposts
77
- ?. filter ( ( { post } ) => post . author . handle !== handle )
78
- ?. map ( ( { post } ) => < PostCard key = { post . uri } post = { post as BSkyPost } /> ) }
79
- </ div >
90
+ < Virtuoso
91
+ useWindowScroll
92
+ totalCount = { feed . length }
93
+ endReached = { ( ) => fetchNextPage ( ) }
94
+ components = { {
95
+ List : forwardRef ( ( props , ref ) => < div ref = { ref } { ...props } className = "flex flex-col gap-2" /> ) ,
96
+ } }
97
+ itemContent = { ( index : number ) => (
98
+ < PostCard key = { filteredPosts [ index ] ?. post . uri } post = { filteredPosts [ index ] ?. post as BSkyPost } />
99
+ ) }
100
+ />
80
101
) ;
81
102
}
82
103
83
104
function Replies ( ) {
84
105
const { t } = useTranslation ( 'app' ) ;
85
106
const { handle } = Route . useParams ( ) ;
86
- const { data : feed , isLoading } = useAuthorFeed ( { handle } ) ;
107
+ const { data, isLoading, fetchNextPage } = useAuthorFeed ( { handle } ) ;
108
+ const feed = data ?. pages . flatMap ( ( page ) => page . feed ) ;
87
109
88
110
if ( isLoading ) return t ( 'loading' ) ;
111
+ if ( ! feed ) return null ;
112
+
113
+ const filteredPosts = feed
114
+ // Filter to only replies
115
+ ?. filter ( ( { post } ) => ( post . record as BSkyPost [ 'record' ] ) . reply ) ;
89
116
90
117
return (
91
- < div className = "flex flex-col gap-2" >
92
- { feed
93
- // Filter to only replies
94
- ?. filter ( ( { post } ) => ( post . record as BSkyPost [ 'record' ] ) . reply )
95
- ?. map ( ( { post } ) => < PostCard key = { post . uri } post = { post as BSkyPost } /> ) }
96
- </ div >
118
+ < Virtuoso
119
+ useWindowScroll
120
+ totalCount = { feed . length }
121
+ endReached = { ( ) => fetchNextPage ( ) }
122
+ components = { {
123
+ List : forwardRef ( ( props , ref ) => < div ref = { ref } { ...props } className = "flex flex-col gap-2" /> ) ,
124
+ } }
125
+ itemContent = { ( index : number ) => (
126
+ < PostCard key = { filteredPosts [ index ] ?. post . uri } post = { filteredPosts [ index ] ?. post as BSkyPost } />
127
+ ) }
128
+ />
97
129
) ;
98
130
}
99
131
100
132
function Media ( ) {
101
133
const { t } = useTranslation ( 'app' ) ;
102
134
const { handle } = Route . useParams ( ) ;
103
- const { data : feed , isLoading } = useAuthorFeed ( { handle } ) ;
135
+ const { data, isLoading, fetchNextPage } = useAuthorFeed ( { handle } ) ;
136
+ const feed = data ?. pages . flatMap ( ( page ) => page . feed ) ;
104
137
105
138
if ( isLoading ) return t ( 'loading' ) ;
139
+ if ( ! feed ) return null ;
140
+
141
+ const filteredPosts = feed
142
+ // Filter to only media
143
+ ?. filter ( ( { post } ) => ( post . record as BSkyPost [ 'record' ] ) . embed ?. $type === 'app.bsky.embed.images' ) ;
106
144
107
145
return (
108
- < div className = "flex flex-col gap-2" >
109
- { feed
110
- // Filter to only media
111
- ?. filter ( ( { post } ) => ( post . record as BSkyPost [ 'record' ] ) . embed ?. $type === 'app.bsky.embed.images' )
112
- ?. map ( ( { post } ) => < PostCard key = { post . uri } post = { post as BSkyPost } /> ) }
113
- </ div >
146
+ < Virtuoso
147
+ useWindowScroll
148
+ totalCount = { feed . length }
149
+ endReached = { ( ) => fetchNextPage ( ) }
150
+ components = { {
151
+ List : forwardRef ( ( props , ref ) => < div ref = { ref } { ...props } className = "flex flex-col gap-2" /> ) ,
152
+ } }
153
+ itemContent = { ( index : number ) => (
154
+ < PostCard key = { filteredPosts [ index ] ?. post . uri } post = { filteredPosts [ index ] ?. post as BSkyPost } />
155
+ ) }
156
+ />
114
157
) ;
115
158
}
116
159
0 commit comments