Skip to content

Commit 163183f

Browse files
committed
chore: rename ready -> channelListInitialized
1 parent 2095dc0 commit 163183f

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

package/src/components/ChannelList/ChannelList.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,13 @@ export const ChannelList = <
342342
}, [channelManager]);
343343

344344
const {
345+
channelListInitialized,
345346
channels,
346347
error,
347348
hasNextPage,
348349
loadingChannels,
349350
loadingNextPage,
350351
loadNextPage,
351-
ready,
352352
refreshing,
353353
refreshList,
354354
reloadList,
@@ -375,7 +375,12 @@ export const ChannelList = <
375375
const channelIdsStr = channels?.reduce((acc, channel) => `${acc}${channel.cid}`, '');
376376

377377
useEffect(() => {
378-
if (channels == null || !ready || staticChannelsActive || !enableOfflineSupport) {
378+
if (
379+
channels == null ||
380+
!channelListInitialized ||
381+
staticChannelsActive ||
382+
!enableOfflineSupport
383+
) {
379384
return;
380385
}
381386

@@ -389,6 +394,7 @@ export const ChannelList = <
389394

390395
const channelsContext = useCreateChannelsContext({
391396
additionalFlatListProps,
397+
channelListInitialized,
392398
channels: channelRenderFilterFn ? channelRenderFilterFn(channels ?? []) : channels,
393399
EmptyStateIndicator,
394400
error,
@@ -414,7 +420,6 @@ export const ChannelList = <
414420
PreviewStatus,
415421
PreviewTitle,
416422
PreviewUnreadCount,
417-
ready,
418423
refreshing,
419424
refreshList,
420425
reloadList,

package/src/components/ChannelList/ChannelListMessenger.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const ChannelListMessengerWithContext = <
8686
const onEndReachedCalledDuringCurrentScrollRef = useRef<boolean>(false);
8787
const {
8888
additionalFlatListProps,
89+
channelListInitialized,
8990
channels,
9091
EmptyStateIndicator,
9192
error,
@@ -99,7 +100,6 @@ const ChannelListMessengerWithContext = <
99100
loadingNextPage,
100101
loadMoreThreshold,
101102
loadNextPage,
102-
ready,
103103
refreshing,
104104
refreshList,
105105
reloadList,
@@ -141,7 +141,7 @@ const ChannelListMessengerWithContext = <
141141
});
142142
}
143143

144-
if (error && !refreshing && !loadingChannels && (channels === null || !ready)) {
144+
if (error && !refreshing && !loadingChannels && (channels === null || !channelListInitialized)) {
145145
return (
146146
<LoadingErrorIndicator
147147
error={error}
@@ -212,6 +212,7 @@ export const ChannelListMessenger = <
212212
) => {
213213
const {
214214
additionalFlatListProps,
215+
channelListInitialized,
215216
channels,
216217
EmptyStateIndicator,
217218
error,
@@ -225,7 +226,6 @@ export const ChannelListMessenger = <
225226
loadingNextPage,
226227
loadMoreThreshold,
227228
loadNextPage,
228-
ready,
229229
refreshing,
230230
refreshList,
231231
reloadList,
@@ -236,6 +236,7 @@ export const ChannelListMessenger = <
236236
<ChannelListMessengerWithContext
237237
{...{
238238
additionalFlatListProps,
239+
channelListInitialized,
239240
channels,
240241
EmptyStateIndicator,
241242
error,
@@ -249,7 +250,6 @@ export const ChannelListMessenger = <
249250
loadingNextPage,
250251
loadMoreThreshold,
251252
loadNextPage,
252-
ready,
253253
refreshing,
254254
refreshList,
255255
reloadList,

package/src/components/ChannelList/hooks/useCreateChannelsContext.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const useCreateChannelsContext = <
77
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
88
>({
99
additionalFlatListProps,
10+
channelListInitialized,
1011
channels,
1112
EmptyStateIndicator,
1213
error,
@@ -32,7 +33,6 @@ export const useCreateChannelsContext = <
3233
PreviewStatus,
3334
PreviewTitle,
3435
PreviewUnreadCount,
35-
ready,
3636
refreshing,
3737
refreshList,
3838
reloadList,
@@ -52,6 +52,7 @@ export const useCreateChannelsContext = <
5252
const channelsContext: ChannelsContextValue<StreamChatGenerics> = useMemo(
5353
() => ({
5454
additionalFlatListProps,
55+
channelListInitialized,
5556
channels,
5657
EmptyStateIndicator,
5758
error,
@@ -77,7 +78,6 @@ export const useCreateChannelsContext = <
7778
PreviewStatus,
7879
PreviewTitle,
7980
PreviewUnreadCount,
80-
ready,
8181
refreshing,
8282
refreshList,
8383
reloadList,
@@ -92,7 +92,7 @@ export const useCreateChannelsContext = <
9292
hasNextPage,
9393
loadingChannels,
9494
loadingNextPage,
95-
ready,
95+
channelListInitialized,
9696
refreshing,
9797
],
9898
);

package/src/components/ChannelList/hooks/usePaginatedChannels.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ const selector = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
4949
nextValue: ChannelManagerState<StreamChatGenerics>,
5050
) =>
5151
({
52+
channelListInitialized: nextValue.initialized,
5253
channels: nextValue.channels,
5354
pagination: nextValue.pagination,
54-
// TODO: rename this properly everywhere
55-
ready: nextValue.initialized,
5655
} as const);
5756

5857
export const usePaginatedChannels = <
@@ -71,7 +70,8 @@ export const usePaginatedChannels = <
7170
const activeChannels = useActiveChannelsRefContext();
7271
const isMountedRef = useIsMountedRef();
7372
const { client } = useChatContext<StreamChatGenerics>();
74-
const { channels, pagination, ready } = useStateStore(channelManager?.state, selector) ?? {};
73+
const { channelListInitialized, channels, pagination } =
74+
useStateStore(channelManager?.state, selector) ?? {};
7575
const hasNextPage = pagination?.hasNext;
7676

7777
const filtersRef = useRef<typeof filters | null>(null);
@@ -268,22 +268,22 @@ export const usePaginatedChannels = <
268268
}, [filterStr, sortStr, channelManager]);
269269

270270
return {
271+
channelListInitialized,
271272
channels,
272273
error,
273274
hasNextPage,
274275
loadingChannels:
275276
activeQueryType.current === 'queryLocalDB'
276277
? true
277-
: // Although channels.length === 0 should come as a given when we have !ready,
278+
: // Although channels.length === 0 should come as a given when we have !channelListInitialized,
278279
// due to the way offline storage works currently we have to do this additional
279280
// check to make sure channels were not populated before the reactive list becomes
280281
// ready. I do not like providing a way to set the ready state, as it should be managed
281282
// in the LLC entirely. Once we move offline support to the LLC, we can remove this check
282283
// too as it'll be redundant.
283-
pagination?.isLoading || (!ready && channels.length === 0),
284+
pagination?.isLoading || (!channelListInitialized && channels.length === 0),
284285
loadingNextPage: pagination?.isLoadingNext,
285286
loadNextPage: channelManager.loadNext,
286-
ready,
287287
refreshing: activeQueryType.current === 'refresh',
288288
refreshList,
289289
reloadList,

package/src/contexts/channelsContext/ChannelsContext.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export type ChannelsContextValue<
4242
* **Note:** Don't use `additionalFlatListProps` to access the FlatList ref, use `setFlatListRef`
4343
*/
4444
additionalFlatListProps: Partial<FlatListProps<Channel<StreamChatGenerics>>>;
45+
/**
46+
* A control prop used to determine whether the first query of the channel list has succeeded.
47+
*/
48+
channelListInitialized: boolean;
4549
/**
4650
* Channels can be either an array of channels or a promise which resolves to an array of channels
4751
*/
@@ -120,7 +124,6 @@ export type ChannelsContextValue<
120124
* Default: [ChannelPreviewMessenger](https://getstream.io/chat/docs/sdk/reactnative/ui-components/channel-preview-messenger/)
121125
*/
122126
Preview: React.ComponentType<ChannelPreviewMessengerProps<StreamChatGenerics>>;
123-
ready: boolean;
124127
/**
125128
* Triggered when the channel list is refreshing, displays a loading spinner at the top of the list
126129
*/

0 commit comments

Comments
 (0)