Skip to content

Commit ec9dd47

Browse files
Merge pull request #341 from GetStream/vishal/channellist-fixes
Fixing ChannelList UX
2 parents a9e181c + 12b5fee commit ec9dd47

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/components/ChannelList/ChannelList.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ import { ChatContext } from '../../context';
2424
*
2525
* @example ../docs/ChannelList.md
2626
*/
27+
const DEFAULT_FILTERS = {};
28+
const DEFAULT_OPTIONS = {};
29+
const DEFAULT_SORT = {};
30+
2731
const ChannelList = (props) => {
2832
const {
2933
List = ChannelListMessenger,
30-
filters = {},
34+
filters = DEFAULT_FILTERS,
3135
lockChannelOrder = false,
3236
onAddedToChannel,
3337
onChannelDeleted,
@@ -37,9 +41,9 @@ const ChannelList = (props) => {
3741
onMessageNew,
3842
onRemovedFromChannel,
3943
onSelect,
40-
options = {},
44+
options = DEFAULT_OPTIONS,
4145
setFlatListRef,
42-
sort = {},
46+
sort = DEFAULT_SORT,
4347
} = props;
4448

4549
const { client } = useContext(ChatContext);

src/components/ChannelList/ChannelListMessenger.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ const ChannelListMessenger = (props) => {
115115
);
116116
};
117117

118-
if (error && !refreshing && !(channels && channels.length)) {
119-
return renderLoadingError();
120-
} else if (loadingChannels) {
118+
if (loadingChannels) {
121119
return renderLoading();
120+
} else if (error && !refreshing && !(channels && channels.length)) {
121+
return renderLoadingError();
122122
} else {
123123
return renderChannels();
124124
}

src/components/ChannelList/hooks/usePaginatedChannels.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import { useEffect, useState } from 'react';
22

33
import { MAX_QUERY_CHANNELS_LIMIT } from '../utils';
44

5-
const wait = (ms) => {
5+
const wait = (ms) =>
66
new Promise((resolve) => {
77
setTimeout(resolve, ms);
88
});
9-
};
109

1110
export const usePaginatedChannels = ({
1211
client,
@@ -26,7 +25,6 @@ export const usePaginatedChannels = ({
2625
if (loadingChannels || loadingNextPage || refreshing) return;
2726

2827
if (queryType === 'reload') {
29-
setChannels([]);
3028
setLoadingChannels(true);
3129
} else if (queryType === 'refresh') {
3230
setRefreshing(true);
@@ -58,12 +56,12 @@ export const usePaginatedChannels = ({
5856
setHasNextPage(channelQueryResponse.length >= newOptions.limit);
5957
setOffset(newChannels.length);
6058
} catch (e) {
61-
setLoadingChannels(false);
62-
setLoadingNextPage(false);
63-
setRefreshing(false);
6459
await wait(2000);
6560

6661
if (retryCount === 3) {
62+
setLoadingChannels(false);
63+
setLoadingNextPage(false);
64+
setRefreshing(false);
6765
console.warn(e);
6866
return setError(true);
6967
}

0 commit comments

Comments
 (0)