Skip to content

Commit 799790c

Browse files
Fixing channellist network recovery
1 parent d803bab commit 799790c

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

src/components/Attachment/Gallery.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ export const Gallery = <At extends UnknownType = DefaultAttachmentType>(
143143
const immutableGalleryImages = images.reduce((returnArray, currentImage) => {
144144
const url = currentImage.image_url || currentImage.thumb_url;
145145
if (url) {
146-
returnArray.push({ url: makeImageCompatibleUrl(url) } as Immutable<
147-
IImageInfo
148-
>);
146+
returnArray.push({
147+
url: makeImageCompatibleUrl(url),
148+
} as Immutable<IImageInfo>);
149149
}
150150
return returnArray;
151151
}, [] as Immutable<IImageInfo>[]);

src/components/ChannelList/ChannelList.tsx

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

33
import {
44
ChannelListMessenger,
@@ -306,6 +306,11 @@ export const ChannelList = <
306306
sort,
307307
});
308308

309+
useEffect(() => {
310+
// TODO: Use sync api endpoint to refresh the list, instead of caliing queryChannels.
311+
refreshList();
312+
}, [forceUpdate]);
313+
309314
// Setup event listeners
310315
useAddedToChannelNotification({
311316
onAddedToChannel,

src/components/ChannelList/hooks/usePaginatedChannels.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const usePaginatedChannels = <
7878

7979
const newOptions = {
8080
limit: options?.limit ?? MAX_QUERY_CHANNELS_LIMIT,
81-
offset: queryType === 'reload' ? 0 : offset,
81+
offset: queryType === 'reload' || queryType === 'refresh' ? 0 : offset,
8282
...options,
8383
};
8484

@@ -90,7 +90,7 @@ export const usePaginatedChannels = <
9090
);
9191

9292
let newChannels;
93-
if (queryType === 'reload') {
93+
if (queryType === 'reload' || queryType === 'refresh') {
9494
newChannels = channelQueryResponse;
9595
} else {
9696
newChannels = [...channels, ...channelQueryResponse];

src/components/ChannelPreview/ChannelPreview.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const UnMemoizedChannelPreview = <
5454
>(
5555
props: ChannelPreviewProps<At, Ch, Co, Ev, Me, Re, Us>,
5656
) => {
57-
const { channel, Preview = ChannelPreviewMessenger } = props;
57+
const { channel, forceUpdate, Preview = ChannelPreviewMessenger } = props;
5858

5959
const { client } = useChatContext<At, Ch, Co, Ev, Me, Re, Us>();
6060

@@ -88,6 +88,10 @@ const UnMemoizedChannelPreview = <
8888
};
8989
}, []);
9090

91+
useEffect(() => {
92+
setUnread(channel.countUnread());
93+
}, [forceUpdate]);
94+
9195
useEffect(() => {
9296
const handleReadEvent = (event: Event<At, Ch, Co, Ev, Me, Re, Us>) => {
9397
if (event.user?.id === client.userID) {
@@ -124,7 +128,9 @@ const areEqual = <
124128
const { last_message_at: previousLast } = prevProps.channel.state;
125129
const { last_message_at: nextLast } = nextProps.channel.state;
126130

127-
return previousLast === nextLast;
131+
return (
132+
previousLast === nextLast && prevProps.forceUpdate === nextProps.forceUpdate
133+
);
128134
};
129135

130136
export const ChannelPreview = React.memo(

0 commit comments

Comments
 (0)