Skip to content

Commit 2b2c72a

Browse files
Merge pull request #447 from GetStream/vishal/channel-list-fix2
ChannelList reload/refresh UX fixes and stream-chat bump
2 parents 9d60a8a + 43fcabc commit 2b2c72a

File tree

15 files changed

+69
-44
lines changed

15 files changed

+69
-44
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,11 @@ yarn-error.log
1111
dist/
1212
lib/
1313
.env*
14-
14+
vendor
15+
pods
16+
.gradle
17+
.idea
18+
build
19+
local.properties
20+
xcuserdata
1521
.tern-port

expo-package/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,10 +1428,10 @@ source-map@^0.5.0:
14281428
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
14291429
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
14301430

1431-
1432-
version "2.0.0"
1433-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-2.0.0.tgz#ca0f5a241cdf0d82d4a8e938311db107428e2533"
1434-
integrity sha512-JWZCSSKBLBTEQXIsR0vGr6lbj9Wl+2KnMhOQnq4CF4AqVEnSV/zd+78z+g8ZwZNjxs3wah+KmjP9kwm2hqHl5Q==
1431+
1432+
version "2.0.2"
1433+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-2.0.2.tgz#b7761d190039a6b93eb2e0107e4f72a79e51791a"
1434+
integrity sha512-NEb4wlZv66I7XF+HofotEraqYVNBrYnR8Hq0u4Giz4mU8qkofoTSp35NwwuXeALBR485jPPYM3F20Fg4CjV3aA==
14351435
dependencies:
14361436
"@babel/runtime" "7.11.2"
14371437
"@stream-io/react-native-simple-markdown" "1.2.1"

native-package/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,10 +1474,10 @@ source-map@^0.5.0:
14741474
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
14751475
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
14761476

1477-
1478-
version "2.0.0"
1479-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-2.0.0.tgz#ca0f5a241cdf0d82d4a8e938311db107428e2533"
1480-
integrity sha512-JWZCSSKBLBTEQXIsR0vGr6lbj9Wl+2KnMhOQnq4CF4AqVEnSV/zd+78z+g8ZwZNjxs3wah+KmjP9kwm2hqHl5Q==
1477+
1478+
version "2.0.2"
1479+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-2.0.2.tgz#b7761d190039a6b93eb2e0107e4f72a79e51791a"
1480+
integrity sha512-NEb4wlZv66I7XF+HofotEraqYVNBrYnR8Hq0u4Giz4mU8qkofoTSp35NwwuXeALBR485jPPYM3F20Fg4CjV3aA==
14811481
dependencies:
14821482
"@babel/runtime" "7.11.2"
14831483
"@stream-io/react-native-simple-markdown" "1.2.1"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"react-native-actionsheet": "2.4.2",
104104
"react-native-image-zoom-viewer": "3.0.1",
105105
"seamless-immutable": "7.1.4",
106-
"stream-chat": "2.7.0",
106+
"stream-chat": "2.9.0",
107107
"styled-components": "5.2.0",
108108
"uuid": "8.3.1"
109109
},

src/components/Channel/Channel.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import {
1313
SendMessageAPIResponse,
1414
StreamChat,
1515
Message as StreamMessage,
16+
UpdatedMessage,
1617
} from 'stream-chat';
17-
import { v4 as uuidv4 } from 'uuid';
1818

1919
import { EmptyStateIndicator as EmptyStateIndicatorDefault } from '../Indicators/EmptyStateIndicator';
2020
import { LoadingErrorIndicator as LoadingErrorIndicatorDefault } from '../Indicators/LoadingErrorIndicator';
@@ -52,6 +52,7 @@ import type {
5252
DefaultUserType,
5353
UnknownType,
5454
} from '../../types/types';
55+
import { generateRandomId } from '../../utils/generateRandomId';
5556

5657
export type ChannelProps<
5758
At extends UnknownType = DefaultAttachmentType,
@@ -111,7 +112,7 @@ export type ChannelProps<
111112
*/
112113
doUpdateMessageRequest?: (
113114
channelId: string,
114-
updatedMessage: StreamMessage<At, Me, Us>,
115+
updatedMessage: UpdatedMessage<At, Ch, Co, Me, Re, Us>,
115116
) => ReturnType<StreamChat<At, Ch, Co, Ev, Me, Re, Us>['updateMessage']>;
116117
emojiData?: MessagesContextValue<At, Ch, Co, Ev, Me, Re, Us>['emojiData'];
117118
/**
@@ -454,7 +455,7 @@ export const Channel = <
454455
attachments,
455456
created_at: new Date(),
456457
html: text,
457-
id: `${client.userID}-${uuidv4()}`,
458+
id: `${client.userID}-${generateRandomId()}`,
458459
mentioned_users:
459460
mentioned_users?.map((userId) => ({
460461
id: userId,

src/components/ChannelList/ChannelListMessenger.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export type ChannelListMessengerProps<
7171
* Function to refresh the channel list that is similar to `reloadList`, but it doesn't wipe out existing channels
7272
* from UI before loading the new ones
7373
*/
74-
refreshList?: () => Promise<void>;
74+
refreshList?: () => void | Promise<void>;
7575

7676
/**
7777
* Removes all the existing channels from UI and loads fresh channels
@@ -152,19 +152,22 @@ export const ChannelListMessenger = <
152152
}, [loadingChannels]);
153153

154154
const HeaderIndicator: React.FC = () => {
155+
if (loadingChannels) return null;
156+
155157
if (!isOnline) {
156158
return <HeaderNetworkDownIndicator />;
157159
} else if (error) {
158160
return <HeaderErrorIndicator onPress={refreshList} />;
159161
}
162+
160163
return null;
161164
};
162165

163166
const renderItem = (channel: Channel<At, Ch, Co, Ev, Me, Re, Us>) => (
164167
<ChannelPreview<At, Ch, Co, Ev, Me, Re, Us> {...props} channel={channel} />
165168
);
166169

167-
if (error && !refreshing && !channels?.length) {
170+
if (error && !refreshing && !loadingChannels && !channels?.length) {
168171
return (
169172
<LoadingErrorIndicator
170173
error={error}

src/components/ChannelList/hooks/usePaginatedChannels.ts

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

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

@@ -61,6 +61,7 @@ export const usePaginatedChannels = <
6161
const [loadingNextPage, setLoadingNextPage] = useState(false);
6262
const [offset, setOffset] = useState(0);
6363
const [refreshing, setRefreshing] = useState(false);
64+
const lastRefresh = useRef(Date.now());
6465

6566
const queryChannels = async (
6667
queryType = '',
@@ -120,7 +121,17 @@ export const usePaginatedChannels = <
120121
};
121122

122123
const loadNextPage = hasNextPage ? queryChannels : undefined;
123-
const refreshList = () => queryChannels('refresh');
124+
const refreshList = () => {
125+
const now = Date.now();
126+
// Only allow pull-to-refresh 5 seconds after last successful refresh.
127+
if (now - lastRefresh.current < 5000 && !error) {
128+
return;
129+
}
130+
131+
lastRefresh.current = Date.now();
132+
return queryChannels('refresh');
133+
};
134+
124135
const reloadList = () => queryChannels('reload');
125136

126137
useEffect(() => {

src/components/Chat/Chat.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export const Chat = <
155155

156156
useEffect(() => {
157157
client?.setUserAgent(`stream-chat-react-native-${Platform.OS}-${version}`);
158+
client.recoverStateOnReconnect = false;
158159
}, []);
159160

160161
const setActiveChannel = (newChannel?: Channel<At, Ch, Co, Ev, Me, Re, Us>) =>

src/components/MessageInput/MessageInput.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
logChatPromiseExecution,
1414
SendFileAPIResponse,
1515
Message as StreamMessage,
16+
UpdatedMessage,
1617
UserResponse,
1718
} from 'stream-chat';
1819

@@ -40,7 +41,7 @@ import {
4041
ImageUpload,
4142
useMessageDetailsForState,
4243
} from './hooks/useMessageDetailsForState';
43-
import { generateRandomId } from './utils/generateRandomId';
44+
import { generateRandomId } from '../../utils/generateRandomId';
4445

4546
import {
4647
AutoCompleteInput,
@@ -791,7 +792,7 @@ export const MessageInput = <
791792
attachments,
792793
mentioned_users: mentionedUsers,
793794
text: prevText,
794-
} as StreamMessage<At, Me, Us>;
795+
} as UpdatedMessage<At, Ch, Co, Me, Re, Us>;
795796

796797
// TODO: Remove this line and show an error when submit fails
797798
clearEditingState();
@@ -838,7 +839,7 @@ export const MessageInput = <
838839
await client.updateMessage({
839840
...editing,
840841
text,
841-
} as StreamMessage<At, Me, Us>);
842+
} as UpdatedMessage<At, Ch, Co, Me, Re, Us>);
842843
}
843844

844845
resetInput();

src/components/MessageInput/hooks/useMessageDetailsForState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from 'react';
22

3-
import { generateRandomId } from '../utils/generateRandomId';
3+
import { generateRandomId } from '../../../utils/generateRandomId';
44

55
import {
66
isEditingBoolean,

0 commit comments

Comments
 (0)