Skip to content

Commit cf402b1

Browse files
committed
fix: chat rooms refetch issue
1 parent 2692120 commit cf402b1

File tree

1 file changed

+18
-1
lines changed
  • packages/components/modules/messages/ChatRoomsList

1 file changed

+18
-1
lines changed

packages/components/modules/messages/ChatRoomsList/index.tsx

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
'use client'
22

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'
413

514
import { Searchbar as DefaultSearchbar, LoadingState } from '@baseapp-frontend/design-system'
615

@@ -37,6 +46,7 @@ const ChatRoomsList: FC<ChatRoomsListProps> = ({
3746

3847
const [isPending, startTransition] = useTransition()
3948
const { control, reset, watch } = useForm({ defaultValues: { search: '' } })
49+
const cursor = useRef<string | null | undefined>(null)
4050

4151
const isInUnreadTab = tab === CHAT_TAB_VALUES.unread
4252
const isInArchivedTab = tab === CHAT_TAB_VALUES.archived
@@ -55,13 +65,20 @@ const ChatRoomsList: FC<ChatRoomsListProps> = ({
5565
})
5666
}
5767

68+
useEffect(() => {
69+
if (data?.chatRooms?.pageInfo?.endCursor) {
70+
cursor.current = data.chatRooms.pageInfo.endCursor
71+
}
72+
}, [data?.chatRooms?.pageInfo?.endCursor])
73+
5874
const handleChange = (event: React.SyntheticEvent, newTab: string) => {
5975
setTab(newTab as ChatTabValues)
6076
startRefetchTransition(() => {
6177
refetch(
6278
{
6379
unreadMessages: newTab === CHAT_TAB_VALUES.unread,
6480
archived: newTab === CHAT_TAB_VALUES.archived,
81+
cursor: cursor.current,
6582
},
6683
{ fetchPolicy: 'store-and-network' },
6784
)

0 commit comments

Comments
 (0)