-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathChannelListMessenger.tsx
64 lines (56 loc) · 2.5 KB
/
ChannelListMessenger.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React, { PropsWithChildren } from 'react';
import { ChatDown, ChatDownProps } from '../ChatDown/ChatDown';
import { LoadingChannels } from '../Loading/LoadingChannels';
import type { APIErrorResponse, Channel, ErrorFromResponse } from 'stream-chat';
import type { DefaultStreamChatGenerics } from '../../types/types';
import { useTranslationContext } from '../../context';
export type ChannelListMessengerProps<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
> = {
/** Whether or not the channel query request returned an errored response */
error: ErrorFromResponse<APIErrorResponse> | null;
/** The channels currently loaded in the list, only defined if `sendChannelsToList` on `ChannelList` is true */
loadedChannels?: Channel<StreamChatGenerics>[];
/** Whether or not channels are currently loading */
loading?: boolean;
/** Custom UI component to display a loading error, defaults to and accepts same props as: [ChatDown](https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChatDown/ChatDown.tsx) */
LoadingErrorIndicator?: React.ComponentType<ChatDownProps>;
/** 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) */
LoadingIndicator?: React.ComponentType;
/** Local state hook that resets the currently loaded channels */
setChannels?: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[]>>;
};
/**
* A preview list of channels, allowing you to select the channel you want to open
*/
export const ChannelListMessenger = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
>(
props: PropsWithChildren<ChannelListMessengerProps<StreamChatGenerics>>,
) => {
const {
children,
error = null,
loading,
LoadingErrorIndicator = ChatDown,
LoadingIndicator = LoadingChannels,
} = props;
const { t } = useTranslationContext('ChannelListMessenger');
if (error) {
return <LoadingErrorIndicator type='Connection Error' />;
}
if (loading) {
return <LoadingIndicator />;
}
return (
<div className='str-chat__channel-list-messenger str-chat__channel-list-messenger-react'>
<div
aria-label={t('aria/Channel list')}
className='str-chat__channel-list-messenger__main str-chat__channel-list-messenger-react__main'
role='listbox'
>
{children}
</div>
</div>
);
};