Skip to content

Commit 63895f2

Browse files
committed
chore: use reactive state
1 parent fe44060 commit 63895f2

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useEffect, useMemo, useRef, useState } from 'react';
22

33
import {
4-
Channel,
54
ChannelFilters,
65
ChannelManager,
76
ChannelManagerState,
@@ -65,7 +64,8 @@ export const usePaginatedChannels = <
6564
// const [channels, setChannels] = useState<Channel<StreamChatGenerics>[] | null>(null);
6665
const [error, setError] = useState<Error | undefined>(undefined);
6766
const [staticChannelsActive, setStaticChannelsActive] = useState<boolean>(false);
68-
const [activeQueryType, setActiveQueryType] = useState<QueryType | null>('queryLocalDB');
67+
// const [activeQueryType, setActiveQueryType] = useState<QueryType | null>('queryLocalDB');
68+
const activeQueryType = useRef<QueryType | null>('queryLocalDB');
6969
// const [hasNextPage, setHasNextPage] = useState<boolean>(false);
7070
const activeChannels = useActiveChannelsRefContext();
7171
const isMountedRef = useIsMountedRef();
@@ -109,7 +109,8 @@ export const usePaginatedChannels = <
109109
setError(undefined);
110110
activeRequestId.current++;
111111
const currentRequestId = activeRequestId.current;
112-
setActiveQueryType(queryType);
112+
// setActiveQueryType(queryType);
113+
activeQueryType.current = queryType;
113114

114115
const newOptions = {
115116
limit: options?.limit ?? MAX_QUERY_CHANNELS_LIMIT,
@@ -161,7 +162,8 @@ export const usePaginatedChannels = <
161162
// querying.current check is needed in order to make sure the next query call doesnt flick an error
162163
// state and then succeed (reconnect case)
163164
if (retryCount === MAX_NUMBER_OF_RETRIES && !isQueryingRef.current) {
164-
setActiveQueryType(null);
165+
// setActiveQueryType(null);
166+
activeQueryType.current = null;
165167
console.warn(err);
166168

167169
setError(
@@ -175,7 +177,8 @@ export const usePaginatedChannels = <
175177
return queryChannels(queryType, retryCount + 1);
176178
}
177179

178-
setActiveQueryType(null);
180+
// setActiveQueryType(null);
181+
activeQueryType.current = null;
179182
};
180183

181184
const refreshList = async () => {
@@ -236,7 +239,8 @@ export const usePaginatedChannels = <
236239
return false;
237240
}
238241

239-
setActiveQueryType(null);
242+
// setActiveQueryType(null);
243+
activeQueryType.current = null;
240244

241245
return true;
242246
};
@@ -284,10 +288,16 @@ export const usePaginatedChannels = <
284288
channels,
285289
error,
286290
hasNextPage,
287-
loadingChannels: activeQueryType === 'queryLocalDB' ? true : pagination.isLoading,
288-
loadingNextPage: activeQueryType === 'loadChannels',
291+
// loadingChannels:
292+
// activeQueryType.current === 'queryLocalDB'
293+
// ? true
294+
// : (activeQueryType.current === 'reload' || activeQueryType.current === null) &&
295+
// channels === null,
296+
loadingChannels:
297+
activeQueryType.current === 'queryLocalDB' || !channelManager ? true : pagination?.isLoading,
298+
loadingNextPage: pagination?.isLoadingNext,
289299
loadNextPage: channelManager?.loadNext,
290-
refreshing: activeQueryType === 'refresh',
300+
refreshing: activeQueryType.current === 'refresh',
291301
refreshList,
292302
reloadList,
293303
staticChannelsActive,

0 commit comments

Comments
 (0)