@@ -10,7 +10,7 @@ import React, {
1010 useRef ,
1111 useState ,
1212} from "react" ;
13- import { CommentView } from "threadiverse" ;
13+ import { CommentView , PageCursor } from "threadiverse" ;
1414import { VListHandle } from "virtua" ;
1515
1616import FeedLoadMoreFailed from "#/features/feed/endItems/FeedLoadMoreFailed" ;
@@ -70,7 +70,7 @@ export default function Comments({
7070 virtualEnabled,
7171} : CommentsProps ) {
7272 const dispatch = useAppDispatch ( ) ;
73- const [ page , setPage ] = useState ( 0 ) ;
73+ const [ cursor , setCursor ] = useState < PageCursor | undefined > ( ) ;
7474 const [ loading , _setLoading ] = useState ( true ) ;
7575 const loadingRef = useRef ( false ) ;
7676 const finishedPagingRef = useRef ( false ) ;
@@ -220,7 +220,7 @@ export default function Comments({
220220 if ( ! ready ) return ;
221221
222222 if ( refresh ) {
223- if ( page === 0 && loadingRef . current ) return ; // Still loading first page
223+ if ( ! cursor && loadingRef . current ) return ; // Still loading first page
224224 finishedPagingRef . current = false ;
225225 } else {
226226 if ( loadingRef . current ) return ;
@@ -229,7 +229,7 @@ export default function Comments({
229229
230230 let response ;
231231
232- const currentPage = refresh ? 1 : page + 1 ;
232+ const currentPage = refresh ? undefined : cursor ;
233233
234234 const reqPostId = postId ;
235235 const reqCommentId = parentCommentId ;
@@ -239,14 +239,11 @@ export default function Comments({
239239 response = await client . getComments ( {
240240 post_id : reqPostId ,
241241 parent_id : parentCommentId ,
242- limit : 60 ,
243242 ...sortParams ,
244243 type_ : "All" ,
245-
244+ limit : 60 ,
246245 max_depth : maxDepth ,
247-
248- saved_only : false ,
249- page : currentPage ,
246+ page_cursor : currentPage ,
250247 } ) ;
251248 } catch ( error ) {
252249 if ( reqPostId === postId && reqCommentId === parentCommentId )
@@ -258,23 +255,23 @@ export default function Comments({
258255 setLoadFailed ( true ) ;
259256 if ( refresh ) {
260257 setComments ( [ ] ) ;
261- setPage ( 0 ) ;
258+ setCursor ( undefined ) ;
262259 }
263260
264261 throw error ;
265262 } finally {
266263 setLoading ( false ) ;
267264 }
268265
269- dispatch ( receivedComments ( response . comments ) ) ;
266+ dispatch ( receivedComments ( response . data ) ) ;
270267
271268 if ( reqPostId !== postId || reqCommentId !== parentCommentId ) return ;
272269
273270 const existingComments = refresh ? [ ] : comments ;
274271
275272 // Remove comments that are already received
276273 let newComments = differenceBy (
277- response . comments ,
274+ response . data ,
278275 existingComments ,
279276 ( c ) => c . comment . id ,
280277 ) ;
@@ -301,7 +298,7 @@ export default function Comments({
301298 ) ;
302299
303300 setComments ( potentialComments ) ;
304- setPage ( currentPage ) ;
301+ setCursor ( response . next_page ) ;
305302 setLoadFailed ( false ) ;
306303
307304 if ( refresh ) scrolledRef . current = false ;
@@ -311,7 +308,7 @@ export default function Comments({
311308 comments ,
312309 dispatch ,
313310 maxDepth ,
314- page ,
311+ cursor ,
315312 parentCommentId ,
316313 postId ,
317314 presentToast ,
0 commit comments