1
1
'use client'
2
2
3
- import { ChangeEventHandler , FC , useCallback , useMemo , useState , useTransition } from 'react'
3
+ import {
4
+ ChangeEventHandler ,
5
+ FC ,
6
+ useCallback ,
7
+ useEffect ,
8
+ useMemo ,
9
+ useRef ,
10
+ useState ,
11
+ useTransition ,
12
+ } from 'react'
4
13
5
14
import { Searchbar as DefaultSearchbar , LoadingState } from '@baseapp-frontend/design-system'
6
15
@@ -37,6 +46,7 @@ const ChatRoomsList: FC<ChatRoomsListProps> = ({
37
46
38
47
const [ isPending , startTransition ] = useTransition ( )
39
48
const { control, reset, watch } = useForm ( { defaultValues : { search : '' } } )
49
+ const cursor = useRef < string | null | undefined > ( null )
40
50
41
51
const isInUnreadTab = tab === CHAT_TAB_VALUES . unread
42
52
const isInArchivedTab = tab === CHAT_TAB_VALUES . archived
@@ -55,13 +65,20 @@ const ChatRoomsList: FC<ChatRoomsListProps> = ({
55
65
} )
56
66
}
57
67
68
+ useEffect ( ( ) => {
69
+ if ( data ?. chatRooms ?. pageInfo ?. endCursor ) {
70
+ cursor . current = data . chatRooms . pageInfo . endCursor
71
+ }
72
+ } , [ data ?. chatRooms ?. pageInfo ?. endCursor ] )
73
+
58
74
const handleChange = ( event : React . SyntheticEvent , newTab : string ) => {
59
75
setTab ( newTab as ChatTabValues )
60
76
startRefetchTransition ( ( ) => {
61
77
refetch (
62
78
{
63
79
unreadMessages : newTab === CHAT_TAB_VALUES . unread ,
64
80
archived : newTab === CHAT_TAB_VALUES . archived ,
81
+ cursor : cursor . current ,
65
82
} ,
66
83
{ fetchPolicy : 'store-and-network' } ,
67
84
)
0 commit comments