1
1
'use client'
2
2
3
3
import { useInfiniteQuery , useQueryClient } from '@tanstack/react-query'
4
- import { useMemo , useState } from 'react'
4
+ import { useEffect , useMemo , useState } from 'react'
5
5
import clsx from 'clsx'
6
+ import { stagger , useAnimate } from 'framer-motion'
6
7
import { produce } from 'immer'
7
8
import type { RecentlyModel } from '@mx-space/api-client'
8
9
import type { InfiniteData } from '@tanstack/react-query'
@@ -25,6 +26,7 @@ import { CommentBoxRoot } from '~/components/widgets/comment/CommentBox'
25
26
import { Comments } from '~/components/widgets/comment/Comments'
26
27
import { PeekLink } from '~/components/widgets/peek/PeekLink'
27
28
import { LoadMoreIndicator } from '~/components/widgets/shared/LoadMoreIndicator'
29
+ import { usePrevious } from '~/hooks/common/use-previous'
28
30
import { sample } from '~/lib/_'
29
31
import { preventDefault } from '~/lib/dom'
30
32
import { apiClient } from '~/lib/request'
@@ -156,16 +158,44 @@ const List = () => {
156
158
}
157
159
const { present } = useModalStack ( )
158
160
161
+ const [ scope , animate ] = useAnimate ( )
162
+
163
+ const getPrevData = usePrevious ( data )
164
+ useEffect ( ( ) => {
165
+ if ( ! data ) return
166
+ const pages = getPrevData ( ) ?. pages
167
+ const count = pages ?. reduce ( ( acc , cur ) => {
168
+ return acc + cur . length
169
+ } , 0 )
170
+
171
+ console . log ( count )
172
+
173
+ animate (
174
+ 'li' ,
175
+ {
176
+ opacity : 1 ,
177
+ y : 0 ,
178
+ } ,
179
+ {
180
+ duration : 0.2 ,
181
+ delay : stagger ( 0.1 , {
182
+ startDelay : 0.15 ,
183
+ from : count ? count - FETCH_SIZE : 0 ,
184
+ } ) ,
185
+ } ,
186
+ )
187
+ } , [ data ] )
188
+
159
189
if ( isLoading ) < Loading useDefaultLoadingText />
160
190
161
191
return (
162
- < ul >
192
+ < ul ref = { scope } >
163
193
{ data ?. pages . map ( ( page ) => {
164
194
return page . map ( ( item ) => {
165
195
return (
166
196
< li
167
197
key = { item . id }
168
- className = "mb-8 grid grid-cols-[40px_auto] flex-col gap-4 space-y-2"
198
+ className = "mb-8 grid translate-y-[50px] grid-cols-[40px_auto] flex-col gap-4 space-y-2 opacity-[0.0001] "
169
199
>
170
200
< div className = "translate-y-6" >
171
201
< img
0 commit comments