Skip to content

Commit 970f90e

Browse files
committed
chore: replaced with uikit-tools hooks and introduced new channelListQueryParams
1 parent 58c79b3 commit 970f90e

File tree

5 files changed

+48
-10
lines changed

5 files changed

+48
-10
lines changed

packages/uikit-chat-hooks/src/channel/useGroupChannelList/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import type { UseGroupChannelList } from '../../types';
44
import { useGroupChannelListWithCollection } from './useGroupChannelListWithCollection';
55
import { useGroupChannelListWithQuery } from './useGroupChannelListWithQuery';
66

7+
/**
8+
* @deprecated This hook is deprecated and will be replaced by the 'uikit-tools' package.
9+
* */
710
export const useGroupChannelList: UseGroupChannelList = (sdk, userId, options) => {
811
if (sdk.isCacheEnabled || options?.enableCollectionWithoutLocalCache) {
912
if (options?.queryCreator) Logger.warn('`queryCreator` is ignored, please use `collectionCreator` instead.');

packages/uikit-chat-hooks/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export interface CustomBidirectionalQueryInterface<Data> {
3333
}
3434

3535
/**
36+
* @deprecated This hook is deprecated and will be replaced by the 'uikit-tools' package.
37+
*
3638
* @interface UseGroupChannelList
3739
* @description interface for group channel list hook
3840
* */

packages/uikit-react-native/src/domain/groupChannelList/types.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
import type React from 'react';
22
import type { FlatListProps } from 'react-native';
33

4+
import type { GroupChannelCollectionParams, GroupChannelFilterParams } from '@sendbird/chat/groupChannel';
45
import type { UseGroupChannelListOptions } from '@sendbird/uikit-chat-hooks';
56
import type { ActionMenuItem } from '@sendbird/uikit-react-native-foundation';
67
import type { SendbirdGroupChannel } from '@sendbird/uikit-utils';
78

89
import type { CommonComponent } from '../../types';
910

11+
export type ChannelListQueryParamsType = Omit<GroupChannelCollectionParams, 'filter'> & GroupChannelFilterParams;
1012
export interface GroupChannelListProps {
1113
Fragment: {
1214
onPressChannel: GroupChannelListProps['List']['onPressChannel'];
1315
onPressCreateChannel: (channelType: GroupChannelType) => void;
1416
renderGroupChannelPreview?: GroupChannelListProps['List']['renderGroupChannelPreview'];
1517
skipTypeSelection?: boolean;
16-
collectionCreator?: UseGroupChannelListOptions['collectionCreator'];
1718
flatListProps?: GroupChannelListProps['List']['flatListProps'];
1819
menuItemCreator?: GroupChannelListProps['List']['menuItemCreator'];
20+
/**
21+
* @description You can specify the query parameters for the channel list.
22+
* @example
23+
* ```
24+
* <GroupChannelListFragment channelListQueryParams={{ limit: 20, includeEmpty: false }} />
25+
* ```
26+
* */
27+
channelListQueryParams?: ChannelListQueryParamsType;
28+
/** @deprecated Please use `channelListQueryParams` instead */
29+
collectionCreator?: UseGroupChannelListOptions['collectionCreator'];
1930
};
2031
Header: {};
2132
List: {

packages/uikit-react-native/src/fragments/createGroupChannelListFragment.tsx

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
22

3-
import { useGroupChannelList } from '@sendbird/uikit-chat-hooks';
4-
import { PASS, useAppState, useFreshCallback } from '@sendbird/uikit-utils';
3+
import { GroupChannelCollection, GroupChannelFilter } from '@sendbird/chat/groupChannel';
4+
import { useGroupChannelList } from '@sendbird/uikit-tools';
5+
import { PASS, SendbirdChatSDK, confirmAndMarkAsDelivered, useAppState, useFreshCallback } from '@sendbird/uikit-utils';
56

67
import StatusComposition from '../components/StatusComposition';
78
import GroupChannelPreviewContainer from '../containers/GroupChannelPreviewContainer';
@@ -18,16 +19,17 @@ const createGroupChannelListFragment = (initModule?: Partial<GroupChannelListMod
1819
return ({
1920
onPressChannel,
2021
onPressCreateChannel,
21-
collectionCreator,
2222
renderGroupChannelPreview,
2323
skipTypeSelection = false,
2424
flatListProps = {},
2525
menuItemCreator = PASS,
26+
channelListQueryParams,
27+
collectionCreator,
2628
}) => {
27-
const { sdk, currentUser, sbOptions, markAsDeliveredWithChannel } = useSendbirdChat();
28-
const { groupChannels, next, loading } = useGroupChannelList(sdk, currentUser?.userId, {
29-
collectionCreator,
30-
enableCollectionWithoutLocalCache: true,
29+
const { sdk, sbOptions, markAsDeliveredWithChannel } = useSendbirdChat();
30+
const { groupChannels, loadMore, initialized } = useGroupChannelList(sdk, {
31+
collectionCreator: getCollectionCreator(sdk, channelListQueryParams, collectionCreator),
32+
markAsDelivered: confirmAndMarkAsDelivered,
3133
});
3234

3335
if (sbOptions.appInfo.deliveryReceiptEnabled) {
@@ -49,13 +51,13 @@ const createGroupChannelListFragment = (initModule?: Partial<GroupChannelListMod
4951
return (
5052
<GroupChannelListModule.Provider>
5153
<GroupChannelListModule.Header />
52-
<StatusComposition loading={loading} LoadingComponent={<GroupChannelListModule.StatusLoading />}>
54+
<StatusComposition loading={!initialized} LoadingComponent={<GroupChannelListModule.StatusLoading />}>
5355
<GroupChannelListModule.List
5456
onPressChannel={onPressChannel}
5557
menuItemCreator={menuItemCreator}
5658
renderGroupChannelPreview={_renderGroupChannelPreview}
5759
groupChannels={groupChannels}
58-
onLoadNext={next}
60+
onLoadNext={loadMore}
5961
flatListProps={{
6062
ListEmptyComponent: <GroupChannelListModule.StatusEmpty />,
6163
contentContainerStyle: { flexGrow: 1 },
@@ -72,4 +74,20 @@ const createGroupChannelListFragment = (initModule?: Partial<GroupChannelListMod
7274
};
7375
};
7476

77+
function getCollectionCreator(
78+
sdk: SendbirdChatSDK,
79+
channelListQueryParams?: GroupChannelListProps['Fragment']['channelListQueryParams'],
80+
deprecatedCreatorProp?: () => GroupChannelCollection,
81+
) {
82+
if (!channelListQueryParams && deprecatedCreatorProp) return deprecatedCreatorProp;
83+
84+
return (defaultParams: GroupChannelListProps['Fragment']['channelListQueryParams']) => {
85+
const params = { ...defaultParams, ...channelListQueryParams };
86+
return sdk.groupChannel.createGroupChannelCollection({
87+
...params,
88+
filter: new GroupChannelFilter(params),
89+
});
90+
};
91+
}
92+
7593
export default createGroupChannelListFragment;

sample/src/screens/uikit/groupChannel/GroupChannelTabs/GroupChannelListScreen.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ const GroupChannelListScreen = () => {
6363
onPressChannel={(channel) => {
6464
navigation.navigate(Routes.GroupChannel, { channelUrl: channel.url });
6565
}}
66+
// channelListQueryParams={{
67+
// includeEmpty: true,
68+
// includeFrozen: false,
69+
// }}
6670
/>
6771
);
6872
};

0 commit comments

Comments
 (0)