Files
cinny/src/app/features/room/Room.tsx
T

93 lines
3.0 KiB
TypeScript
Raw Normal View History

2025-06-18 17:42:53 -05:00
/* eslint-disable no-nested-ternary */
2024-07-18 18:50:20 +05:30
import React, { useCallback } from 'react';
import { Box, Line } from 'folds';
import { useParams } from 'react-router-dom';
2024-07-18 18:50:20 +05:30
import { isKeyHotkey } from 'is-hotkey';
import { RoomView } from './RoomView';
import { MembersDrawer } from './MembersDrawer';
import { ScreenSize, useScreenSizeContext } from '../../hooks/useScreenSize';
import { useSetting } from '../../state/hooks/settings';
import { settingsAtom } from '../../state/settings';
import { PowerLevelsContextProvider, usePowerLevels } from '../../hooks/usePowerLevels';
import { useRoom } from '../../hooks/useRoom';
2024-07-18 18:50:20 +05:30
import { useKeyDown } from '../../hooks/useKeyDown';
import { markAsRead } from '../../../client/action/notifications';
2024-07-22 16:17:19 +05:30
import { useMatrixClient } from '../../hooks/useMatrixClient';
import { useRoomMembers } from '../../hooks/useRoomMembers';
2025-05-23 01:24:32 -05:00
import { CallView } from '../call/CallView';
2025-05-22 20:02:35 -05:00
import { useCallState } from '../../pages/client/call/CallProvider';
2025-06-18 17:42:53 -05:00
import { RoomViewHeader } from './RoomViewHeader';
export function Room() {
const { eventId } = useParams();
const room = useRoom();
2024-07-22 16:17:19 +05:30
const mx = useMatrixClient();
const [isDrawer] = useSetting(settingsAtom, 'isPeopleDrawer');
2025-02-26 21:44:53 +11:00
const [hideActivity] = useSetting(settingsAtom, 'hideActivity');
2025-05-10 08:58:32 -05:00
const { isChatOpen } = useCallState();
const screenSize = useScreenSizeContext();
const powerLevels = usePowerLevels(room);
2025-05-08 18:01:27 -05:00
const members = useRoomMembers(mx, room?.roomId);
2024-07-18 18:50:20 +05:30
useKeyDown(
window,
useCallback(
(evt) => {
2024-09-08 22:53:17 +10:00
if (isKeyHotkey('escape', evt)) {
2025-02-26 21:44:53 +11:00
markAsRead(mx, room.roomId, hideActivity);
2024-07-18 18:50:20 +05:30
}
},
2025-02-26 21:44:53 +11:00
[mx, room.roomId, hideActivity]
2024-07-18 18:50:20 +05:30
)
);
return (
<PowerLevelsContextProvider value={powerLevels}>
2025-05-08 18:01:27 -05:00
<Box
grow="Yes"
style={{
width: '100%',
height: '100%',
display: 'flex',
2025-06-18 17:42:53 -05:00
flexDirection: 'column',
2025-05-08 18:01:27 -05:00
}}
>
2025-06-18 17:42:53 -05:00
{room.isCallRoom() && <RoomViewHeader />}
<Box
grow="Yes"
style={{
width: '100%',
height: '100%',
display: 'flex',
flexDirection: 'row',
}}
>
<CallView room={room} />
{(!room.isCallRoom() || isChatOpen) && (
<Box
grow="Yes"
style={{
width: room.isCallRoom() ? (isChatOpen ? '40%' : '0%') : '100%',
height: '100%',
display: 'flex',
flexDirection: 'column',
}}
>
<Box style={{ flex: 1, minHeight: 0, overflowY: 'auto', background: '#fff' }}>
<RoomView room={room} eventId={eventId} />
</Box>
2025-05-10 08:58:32 -05:00
</Box>
2025-06-18 17:42:53 -05:00
)}
{screenSize === ScreenSize.Desktop && !room.isCallRoom() && isDrawer && (
<>
<Line variant="Background" direction="Vertical" size="300" />
<MembersDrawer key={room.roomId} room={room} members={members} />
</>
)}
</Box>
</Box>
</PowerLevelsContextProvider>
);
}