Skip to content

Commit eeefd87

Browse files
committed
chore(demo): show channel to read only if cannot join
1 parent c023d8b commit eeefd87

4 files changed

Lines changed: 70 additions & 14 deletions

File tree

examples/vite/src/ChatLayout/Panels.tsx

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ import { useAppSettingsSelector } from '../AppSettings/state';
2727
import { DESKTOP_LAYOUT_BREAKPOINT } from './constants.ts';
2828
import { SidebarResizeHandle, ThreadResizeHandle } from './Resize.tsx';
2929
import { ReturnToSkipNavigation } from '../AccessibilityNavigation/ReturnToSkipNavigation.tsx';
30-
import { PublicChannelOverlay } from '../PublicChannelOverlay/PublicChannelOverlay.tsx';
30+
import {
31+
PublicChannelComposerBanner,
32+
PublicChannelOverlay,
33+
usePublicChannelState,
34+
} from '../PublicChannelOverlay/PublicChannelOverlay.tsx';
3135
import { useSidebar } from './SidebarContext.tsx';
3236
import { ThreadStateSync } from './Sync.tsx';
3337

@@ -62,6 +66,23 @@ const ChannelThreadPanel = () => {
6266
);
6367
};
6468

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+
6586
const ResponsiveChannelPanels = () => {
6687
const { thread } = useChannelStateContext('ResponsiveChannelPanels');
6788
const isThreadOpen = !!thread;
@@ -84,14 +105,7 @@ const ResponsiveChannelPanels = () => {
84105
)}
85106
<ReturnToSkipNavigation />
86107
<AIStateIndicator />
87-
<MessageComposer
88-
additionalTextareaProps={{
89-
id: CHANNEL_MESSAGE_COMPOSER_TEXTAREA_TARGET_ID,
90-
}}
91-
audioRecordingEnabled
92-
maxRows={10}
93-
asyncMessagesMultiSendEnabled
94-
/>
108+
<MessageComposerOrBanner />
95109
<PublicChannelOverlay />
96110
</div>
97111
</Window>

examples/vite/src/PublicChannelOverlay/PublicChannelOverlay.scss

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.app-public-channel-overlay {
22
position: absolute;
33
inset: 0;
4-
z-index: 1;
4+
z-index: 3;
55
display: flex;
66
align-items: center;
77
justify-content: center;
@@ -85,3 +85,20 @@
8585
width: 20px;
8686
}
8787
}
88+
89+
.app-public-channel-composer-banner {
90+
display: flex;
91+
align-items: center;
92+
justify-content: center;
93+
width: 100%;
94+
min-height: 56px;
95+
padding: 16px;
96+
border-top: 1px solid var(--str-chat__border-color);
97+
}
98+
99+
.app-public-channel-composer-banner__text {
100+
margin: 0;
101+
font: var(--str-chat__font-caption-default);
102+
color: var(--str-chat__text-secondary);
103+
text-align: center;
104+
}

examples/vite/src/PublicChannelOverlay/PublicChannelOverlay.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@ import {
1212

1313
import './PublicChannelOverlay.scss';
1414

15-
export const PublicChannelOverlay = () => {
15+
export const usePublicChannelState = () => {
1616
const { client } = useChatContext();
1717
const { channel } = useChannelStateContext();
1818
const members = useChannelMembersState(channel);
1919
const membership = members[client.userID!] as ChannelMemberResponse | undefined;
20-
const { addNotification } = useNotificationApi();
21-
const [joining, setJoining] = useState(false);
2220

2321
const isMember = typeof membership?.channel_role === 'string';
2422
const canJoin = channel.data?.own_capabilities?.includes('join-channel');
2523

24+
return { canJoin, channel, client, isMember };
25+
};
26+
27+
export const PublicChannelOverlay = () => {
28+
const { canJoin, channel, client, isMember } = usePublicChannelState();
29+
const { addNotification } = useNotificationApi();
30+
const [joining, setJoining] = useState(false);
31+
2632
const handleJoin = useCallback(async () => {
2733
setJoining(true);
2834
try {
@@ -72,3 +78,17 @@ export const PublicChannelOverlay = () => {
7278
</div>
7379
);
7480
};
81+
82+
export const PublicChannelComposerBanner = () => {
83+
const { canJoin, isMember } = usePublicChannelState();
84+
85+
if (isMember || canJoin) return null;
86+
87+
return (
88+
<div className='app-public-channel-composer-banner'>
89+
<p className='app-public-channel-composer-banner__text'>
90+
You can only view this conversation
91+
</p>
92+
</div>
93+
);
94+
};

examples/vite/src/index.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,12 @@ body {
225225
}
226226

227227
.str-chat__tooltip {
228-
z-index: 10;
228+
z-index: 2;
229+
}
230+
231+
.str-chat__notification-list,
232+
.str-chat__dialog-overlay {
233+
z-index: 4;
229234
}
230235

231236
@media (max-width: 767px) {

0 commit comments

Comments
 (0)