Skip to content

Commit c014b1f

Browse files
authored
fix: forward error object to LoadingErrorIndicator in ChannelList (#2768)
1 parent e6d5a7f commit c014b1f

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src/components/ChannelList/ChannelList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import type { ChatContextValue } from '../../context';
4242
import type { ChannelAvatarProps } from '../Avatar';
4343
import type { TranslationContextValue } from '../../context/TranslationContext';
4444
import type { PaginatorProps } from '../../types/types';
45+
import type { LoadingErrorIndicatorProps } from '../Loading';
4546

4647
const DEFAULT_FILTERS = {};
4748
const DEFAULT_OPTIONS = {};
@@ -86,7 +87,7 @@ export type ChannelListProps = {
8687
/** Custom UI component to display the container for the queried channels, defaults to and accepts same props as: [ChannelListMessenger](https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelList/ChannelListMessenger.tsx) */
8788
List?: React.ComponentType<ChannelListMessengerProps>;
8889
/** Custom UI component to display the loading error indicator, defaults to component that renders null */
89-
LoadingErrorIndicator?: React.ComponentType;
90+
LoadingErrorIndicator?: React.ComponentType<LoadingErrorIndicatorProps>;
9091
/** Custom UI component to display the loading state, defaults to and accepts same props as: [LoadingChannels](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Loading/LoadingChannels.tsx) */
9192
LoadingIndicator?: React.ComponentType;
9293
/** When true, channels won't dynamically sort by most recent message */

src/components/ChannelList/ChannelListMessenger.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { APIErrorResponse, Channel, ErrorFromResponse } from 'stream-chat';
55
import { LoadingChannels } from '../Loading/LoadingChannels';
66
import { NullComponent } from '../UtilityComponents';
77
import { useTranslationContext } from '../../context';
8+
import type { LoadingErrorIndicatorProps } from '../Loading';
89

910
export type ChannelListMessengerProps = {
1011
/** Whether the channel query request returned an errored response */
@@ -14,7 +15,7 @@ export type ChannelListMessengerProps = {
1415
/** Whether the channels are currently loading */
1516
loading?: boolean;
1617
/** Custom UI component to display the loading error indicator, defaults to component that renders null */
17-
LoadingErrorIndicator?: React.ComponentType;
18+
LoadingErrorIndicator?: React.ComponentType<LoadingErrorIndicatorProps>;
1819
/** Custom UI component to display a loading indicator, defaults to and accepts same props as: [LoadingChannels](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Loading/LoadingChannels.tsx) */
1920
LoadingIndicator?: React.ComponentType;
2021
/** Local state hook that resets the currently loaded channels */
@@ -37,7 +38,7 @@ export const ChannelListMessenger = (
3738
const { t } = useTranslationContext('ChannelListMessenger');
3839

3940
if (error) {
40-
return <LoadingErrorIndicator />;
41+
return <LoadingErrorIndicator error={error} />;
4142
}
4243

4344
if (loading) {

src/components/ChannelList/__tests__/ChannelList.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,28 @@ describe('ChannelList', () => {
354354
expect(results).toHaveNoViolations();
355355
});
356356

357+
it('provides the error object to LoadingErrorIndicator', async () => {
358+
useMockedApis(chatClient, [erroredPostApi()]);
359+
jest.spyOn(console, 'warn').mockImplementationOnce(() => null);
360+
361+
const LoadingErrorIndicator = (props) => <div>{props.error.message}</div>;
362+
363+
await act(async () => {
364+
await render(
365+
<Chat client={chatClient}>
366+
<ChannelList
367+
filters={{}}
368+
LoadingErrorIndicator={LoadingErrorIndicator}
369+
options={{ presence: true, state: true, watch: true }}
370+
Preview={ChannelPreviewComponent}
371+
/>
372+
</Chat>,
373+
);
374+
});
375+
376+
expect(screen.getByText('StreamChat error HTTP code: 500')).toBeInTheDocument();
377+
});
378+
357379
it('should render loading indicator before the first channel list load and on reload', async () => {
358380
const channelsQueryStatesHistory = [];
359381
const channelListMessengerLoadingHistory = [];

src/components/Loading/LoadingErrorIndicator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useTranslationContext } from '../../context/TranslationContext';
44

55
export type LoadingErrorIndicatorProps = {
66
/** Error object */
7-
error?: Error;
7+
error?: Error | null;
88
};
99

1010
/**

0 commit comments

Comments
 (0)