-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathChannelHeader.tsx
More file actions
86 lines (78 loc) · 3.38 KB
/
ChannelHeader.tsx
File metadata and controls
86 lines (78 loc) · 3.38 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React from 'react';
import { type ChannelAvatarProps, ChannelAvatar as DefaultAvatar } from '../Avatar';
import { TypingIndicatorHeader } from '../TypingIndicator/TypingIndicatorHeader';
import { useChannelHeaderOnlineStatus } from './hooks/useChannelHeaderOnlineStatus';
import { useChannelPreviewInfo } from '../ChannelListItem/hooks/useChannelPreviewInfo';
import { useChannelStateContext } from '../../context/ChannelStateContext';
import { useChatContext } from '../../context/ChatContext';
import { useComponentContext } from '../../context/ComponentContext';
import { useTypingContext } from '../../context/TypingContext';
import clsx from 'clsx';
const ChannelHeaderSubtitle = () => {
const { channelConfig } = useChannelStateContext('ChannelHeaderSubtitle');
const { client } = useChatContext('ChannelHeaderSubtitle');
const { typing = {} } = useTypingContext('ChannelHeaderSubtitle');
const onlineStatusText = useChannelHeaderOnlineStatus();
const typingInChannel = Object.values(typing).filter(
({ parent_id, user }) => user?.id !== client.user?.id && !parent_id,
);
const hasTyping = channelConfig?.typing_events !== false && typingInChannel.length > 0;
if (!hasTyping && !onlineStatusText) return null;
return (
<div className='str-chat__channel-header__data__subtitle'>
<span
className='str-chat__subtitle-content-transition'
key={hasTyping ? 'typing' : 'default'}
>
{hasTyping ? <TypingIndicatorHeader /> : onlineStatusText}
</span>
</div>
);
};
export type ChannelHeaderProps = {
/** UI component to display an avatar, defaults to [Avatar](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Avatar/Avatar.tsx) component and accepts the same props as: [ChannelAvatar](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Avatar/ChannelAvatar.tsx) */
Avatar?: React.ComponentType<ChannelAvatarProps>;
/** Manually set the image to render, defaults to the Channel image */
image?: string;
/** Set title manually */
title?: string;
};
/**
* The ChannelHeader component renders some basic information about a Channel.
*/
export const ChannelHeader = (props: ChannelHeaderProps) => {
const { Avatar = DefaultAvatar, image: overrideImage, title: overrideTitle } = props;
const { channel } = useChannelStateContext();
const { navOpen } = useChatContext();
const { SidebarToggle } = useComponentContext();
const { displayImage, displayTitle, groupChannelDisplayInfo } = useChannelPreviewInfo({
channel,
overrideImage,
overrideTitle,
});
return (
<div
className={clsx('str-chat__channel-header', {
'str-chat__channel-header--sidebar-collapsed': !navOpen,
})}
>
<div className='str-chat__channel-header__start'>
{!navOpen && SidebarToggle && <SidebarToggle />}
</div>
<div className='str-chat__channel-header__data'>
<div className='str-chat__channel-header__data__title'>{displayTitle}</div>
<ChannelHeaderSubtitle />
</div>
<div className='str-chat__channel-header__end'>
<Avatar
className='str-chat__avatar--channel-header'
displayMembers={groupChannelDisplayInfo?.members}
imageUrl={displayImage}
overflowCount={groupChannelDisplayInfo?.overflowCount}
size='lg'
userName={displayTitle}
/>
</div>
</div>
);
};