Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow complete channel list throttled reload on internet connection recovery #2123

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docusaurus/docs/React/components/core-components/channel-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,39 @@ Custom UI component to display the channel preview in the list.
| --------- | ---------------------------------------------------------------------------------------------------- |
| component | <GHComponentLink text='ChannelPreviewMessenger' path='/ChannelPreview/ChannelPreviewMessenger.tsx'/> |

### recoveryThrottleIntervalMs

Custom interval during which the recovery channel list queries will be prevented. This is to avoid firing unnecessary queries during internet connection fluctuation. Recovery channel query is triggered upon internet connection recovery and leads to complete channel list reload with pagination offset 0. The minimum throttle interval is 2000ms. The default throttle interval is 5000ms.

The channel list recovery mechanism described here (applying `recoveryThrottleIntervalMs`) **is activated only if the `StreamChat` client's channel list recovery mechanism is disabled**. The `StreamChat` recovery mechanism can be disabled when initiating the client instance through the `options` parameter:

```typescript jsx
import { StreamChat } from 'stream-chat';
import { ChannelList, Chat } from 'stream-chat-react';

// ... get apiKey, filters, sort, options

const client = new StreamChat(apiKey, {recoverStateOnReconnect: false});
const App = () => (
<Chat client={client} >
{/** ... */}
<ChannelList
filters={filters}
sort={sort}
options={options}
recoveryThrottleIntervalMs={3000}
{/** other props... */}
/>
{/** ... */}
</Chat>
);

```

| Type | Default |
|--------|---------|
| number | 5000 |

### renderChannels

Function to override the default behavior when rendering channels, so this function is called instead of rendering the Preview directly.
Expand Down
9 changes: 9 additions & 0 deletions src/components/ChannelList/ChannelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ export type ChannelListProps<
Paginator?: React.ComponentType<PaginatorProps | LoadMorePaginatorProps>;
/** Custom UI component to display the channel preview in the list, defaults to and accepts same props as: [ChannelPreviewMessenger](https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelPreview/ChannelPreviewMessenger.tsx) */
Preview?: React.ComponentType<ChannelPreviewUIComponentProps<StreamChatGenerics>>;
/**
* Custom interval during which the recovery channel list queries will be prevented.
* This is to avoid firing unnecessary queries during internet connection fluctuation.
* Recovery channel query is triggered upon `connection.recovered` and leads to complete channel list reload with pagination offset 0.
* The minimum throttle interval is 2000ms. The default throttle interval is 5000ms.
*/
recoveryThrottleIntervalMs?: number;
/** Function to override the default behavior when rendering channels, so this function is called instead of rendering the Preview directly */
renderChannels?: (
channels: Channel<StreamChatGenerics>[],
Expand Down Expand Up @@ -167,6 +174,7 @@ const UnMemoizedChannelList = <
options,
Paginator = LoadMorePaginator,
Preview,
recoveryThrottleIntervalMs,
renderChannels,
sendChannelsToList = false,
setActiveChannelOnMount = true,
Expand Down Expand Up @@ -256,6 +264,7 @@ const UnMemoizedChannelList = <
sort || DEFAULT_SORT,
options || DEFAULT_OPTIONS,
activeChannelHandler,
recoveryThrottleIntervalMs,
);

const loadedChannels = channelRenderFilterFn ? channelRenderFilterFn(channels) : channels;
Expand Down
Loading
Loading