11import clsx from 'clsx' ;
2- import type {
3- ChannelFilters ,
4- ChannelMemberResponse ,
5- ChannelOptions ,
6- ChannelSort ,
7- } from 'stream-chat' ;
8- import { useCallback , useEffect , useRef } from 'react' ;
2+ import type { ChannelFilters , ChannelOptions , ChannelSort } from 'stream-chat' ;
3+ import { useEffect , useRef } from 'react' ;
94import {
105 AIStateIndicator ,
116 Channel ,
@@ -26,14 +21,17 @@ import {
2621 useChatContext ,
2722 type ChatViewSelectorEntry ,
2823 useThreadsViewContext ,
29- Button ,
30- useChannelMembersState ,
3124} from 'stream-chat-react' ;
3225
3326import { useAppSettingsSelector } from '../AppSettings/state' ;
3427import { DESKTOP_LAYOUT_BREAKPOINT } from './constants.ts' ;
3528import { SidebarResizeHandle , ThreadResizeHandle } from './Resize.tsx' ;
3629import { ReturnToSkipNavigation } from '../AccessibilityNavigation/ReturnToSkipNavigation.tsx' ;
30+ import {
31+ PublicChannelComposerBanner ,
32+ PublicChannelOverlay ,
33+ usePublicChannelState ,
34+ } from '../PublicChannelOverlay/PublicChannelOverlay.tsx' ;
3735import { useSidebar } from './SidebarContext.tsx' ;
3836import { ThreadStateSync } from './Sync.tsx' ;
3937
@@ -68,6 +66,23 @@ const ChannelThreadPanel = () => {
6866 ) ;
6967} ;
7068
69+ const MessageComposerOrBanner = ( ) => {
70+ const { canJoin, isMember } = usePublicChannelState ( ) ;
71+
72+ if ( ! isMember && ! canJoin ) return < PublicChannelComposerBanner /> ;
73+
74+ return (
75+ < MessageComposer
76+ additionalTextareaProps = { {
77+ id : CHANNEL_MESSAGE_COMPOSER_TEXTAREA_TARGET_ID ,
78+ } }
79+ audioRecordingEnabled
80+ maxRows = { 10 }
81+ asyncMessagesMultiSendEnabled
82+ />
83+ ) ;
84+ } ;
85+
7186const ResponsiveChannelPanels = ( ) => {
7287 const { thread } = useChannelStateContext ( 'ResponsiveChannelPanels' ) ;
7388 const isThreadOpen = ! ! thread ;
@@ -82,56 +97,24 @@ const ResponsiveChannelPanels = () => {
8297 < WithDragAndDropUpload className = 'app-chat-view__channel-main' >
8398 < Window >
8499 < ChannelHeader Avatar = { ChannelAvatar } />
85- { messageListType === 'virtualized' ? (
86- < VirtualizedMessageList returnAllReadData shouldGroupByUser />
87- ) : (
88- < MessageList returnAllReadData />
89- ) }
90- < ReturnToSkipNavigation />
91- < AIStateIndicator />
92- < MessageComposer
93- additionalTextareaProps = { {
94- id : CHANNEL_MESSAGE_COMPOSER_TEXTAREA_TARGET_ID ,
95- } }
96- audioRecordingEnabled
97- maxRows = { 10 }
98- asyncMessagesMultiSendEnabled
99- />
100+ < div className = 'app-chat-view__channel-body' >
101+ { messageListType === 'virtualized' ? (
102+ < VirtualizedMessageList returnAllReadData shouldGroupByUser />
103+ ) : (
104+ < MessageList returnAllReadData />
105+ ) }
106+ < ReturnToSkipNavigation />
107+ < AIStateIndicator />
108+ < MessageComposerOrBanner />
109+ < PublicChannelOverlay />
110+ </ div >
100111 </ Window >
101112 </ WithDragAndDropUpload >
102113 < ChannelThreadPanel />
103114 </ div >
104115 ) ;
105116} ;
106117
107- const HeaderStartContent = ( ) => {
108- const { client } = useChatContext ( ) ;
109- const { channel } = useChannelStateContext ( ) ;
110- const members = useChannelMembersState ( channel ) ;
111- const membership = members [ client . userID ! ] as ChannelMemberResponse | undefined ;
112-
113- const isMember = typeof membership ?. channel_role === 'string' ;
114- const canJoin = channel . data ?. own_capabilities ?. includes ( 'join-channel' ) ;
115-
116- const handleClick = useCallback ( ( ) => {
117- if ( isMember ) {
118- channel . removeMembers ( [ client . userID ! ] ) . then ( ( ) => {
119- channel . watch ( ) ;
120- } ) ;
121- } else {
122- channel . addMembers ( [ client . userID ! ] ) ;
123- }
124- } , [ isMember ] ) ;
125-
126- if ( ! canJoin ) return null ;
127-
128- return (
129- < Button onClick = { handleClick } variant = 'secondary' appearance = 'outline' size = 'sm' >
130- { isMember ? 'Leave' : 'Join' }
131- </ Button >
132- ) ;
133- } ;
134-
135118export const ChannelsPanels = ( {
136119 filters,
137120 iconOnly,
@@ -193,7 +176,7 @@ export const ChannelsPanels = ({
193176 </ WithComponents >
194177 </ div >
195178 < SidebarResizeHandle layoutRef = { channelsLayoutRef } />
196- < WithComponents overrides = { { TypingIndicator, HeaderStartContent } } >
179+ < WithComponents overrides = { { TypingIndicator } } >
197180 < Channel >
198181 < ResponsiveChannelPanels />
199182 </ Channel >
0 commit comments