show room access indicator on room header

This commit is contained in:
Ajay Bura 2026-08-28 17:20:22 +05:30
commit bd53aaa96a
3 changed files with 51 additions and 8 deletions

View file

@ -0,0 +1,41 @@
import { Icon, Icons, IconSrc, Text, Tooltip, TooltipProvider } from 'folds';
import React from 'react';
import { JoinRule } from '../../types/matrix/room';
import { useClient } from '../hooks/useClient';
import { useObservableValue } from '../hooks/useObservableValue';
import { useRoomJoinRuleLabel } from './JoinRulesSwitcher';
export const getRoomAccessIconSrc = (joinRule?: JoinRule): IconSrc | undefined => {
if (!joinRule) return Icons.Lock;
if (joinRule === 'public') return Icons.Globe;
if (joinRule === 'invite' || joinRule === 'knock' || joinRule === 'private') {
return Icons.Lock;
}
return undefined;
};
export function RoomAccessIndicator({ roomId }: { roomId: string }) {
const ct = useClient();
const roomToJoinRule = useObservableValue(ct.roomToJoinRule);
const ruleToLabels = useRoomJoinRuleLabel();
const iconSrc = getRoomAccessIconSrc(roomToJoinRule.get(roomId));
if (!iconSrc) return null;
return (
<TooltipProvider
position="Right"
align="Center"
tooltip={
<Tooltip>
<Text size="L400">{ruleToLabels[roomToJoinRule.get(roomId) ?? 'private']}</Text>
</Tooltip>
}
>
{(triggerRef) => <Icon ref={triggerRef} opacity={0.8} src={iconSrc} size="50" />}
</TooltipProvider>
);
}

View file

@ -70,6 +70,7 @@ import {
import { roomToNotificationsAtom } from '../../state/room/roomToNotifications';
import { ContainerColor } from '../../styles/ContainerColor.css';
import { RoomSettingsPage } from '../../state/roomSettings';
import { RoomAccessIndicator } from '../../components/RoomAccessIndicator';
type RoomMenuProps = {
requestClose: () => void;
@ -352,9 +353,12 @@ export function RoomViewHeader({ callView }: { callView?: boolean }) {
</Avatar>
)}
<Box direction="Column">
<Text size={topic ? 'H5' : 'H3'} truncate>
{name}
</Text>
<Box grow="Yes" alignItems="Center" gap="200">
<Text size={topic ? 'H5' : 'H3'} truncate>
{name}
</Text>
<RoomAccessIndicator roomId={roomId} />
</Box>
{topic && (
<UseStateProvider initial={false}>
{(viewTopic, setViewTopic) => (

View file

@ -92,6 +92,7 @@ import { getJoinRoomStateId } from '../../../../client/storage/collections';
import { useAllJoinedRoomsSet } from '../../../hooks/useGetRoom';
import { unreadRoomsAtom } from '../../../state/room/roomToUnread';
import { useRoomsUnread } from '../../../state/hooks/unread';
import { RoomAccessIndicator } from '../../../components/RoomAccessIndicator';
type SpaceMenuProps = {
requestClose: () => void;
@ -239,11 +240,8 @@ type SpaceHeaderProps = {
spaceName: string;
};
function SpaceHeader({ spaceName }: SpaceHeaderProps) {
const ct = useClient();
const spaceId = useSpace();
const [menuAnchor, setMenuAnchor] = useState<RectCords>();
const roomToJoinRule = useObservableValue(ct.roomToJoinRule);
const joinRule = roomToJoinRule.get(spaceId);
const handleOpenMenu: MouseEventHandler<HTMLButtonElement> = (evt) => {
const cords = evt.currentTarget.getBoundingClientRect();
@ -257,11 +255,11 @@ function SpaceHeader({ spaceName }: SpaceHeaderProps) {
<>
<PageNavHeader>
<Box alignItems="Center" grow="Yes" gap="300">
<Box grow="Yes" alignItems="Center" gap="100">
<Box grow="Yes" alignItems="Center" gap="200">
<Text size="H4" truncate>
{spaceName}
</Text>
{joinRule !== 'public' && <Icon src={Icons.Lock} size="50" />}
<RoomAccessIndicator roomId={spaceId} />
</Box>
<Box shrink="No">
<IconButton aria-pressed={!!menuAnchor} variant="Background" onClick={handleOpenMenu}>