mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-04 14:30:29 +03:00
Simplify RoomNavUser
Discard future functionality since it probably won't exist in time for merging this PR
This commit is contained in:
parent
77f8a0409a
commit
4be70422b1
1 changed files with 23 additions and 128 deletions
|
|
@ -1,19 +1,8 @@
|
||||||
import {
|
import { Avatar, Box, Icon, Icons, Text } from 'folds';
|
||||||
Avatar,
|
import React from 'react';
|
||||||
Box,
|
|
||||||
config,
|
|
||||||
Icon,
|
|
||||||
IconButton,
|
|
||||||
Icons,
|
|
||||||
Text,
|
|
||||||
Tooltip,
|
|
||||||
TooltipProvider,
|
|
||||||
} from 'folds';
|
|
||||||
import React, { useState } from 'react';
|
|
||||||
import { Room } from 'matrix-js-sdk';
|
import { Room } from 'matrix-js-sdk';
|
||||||
import { useFocusWithin, useHover } from 'react-aria';
|
|
||||||
import { CallMembership } from 'matrix-js-sdk/lib/matrixrtc/CallMembership';
|
import { CallMembership } from 'matrix-js-sdk/lib/matrixrtc/CallMembership';
|
||||||
import { NavItem, NavItemContent, NavItemOptions } from '../../components/nav';
|
import { NavButton, NavItem, NavItemContent } from '../../components/nav';
|
||||||
import { UserAvatar } from '../../components/user-avatar';
|
import { UserAvatar } from '../../components/user-avatar';
|
||||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||||
import { useCallState } from '../../pages/client/call/CallProvider';
|
import { useCallState } from '../../pages/client/call/CallProvider';
|
||||||
|
|
@ -29,15 +18,6 @@ type RoomNavUserProps = {
|
||||||
export function RoomNavUser({ room, callMembership }: RoomNavUserProps) {
|
export function RoomNavUser({ room, callMembership }: RoomNavUserProps) {
|
||||||
const mx = useMatrixClient();
|
const mx = useMatrixClient();
|
||||||
const useAuthentication = useMediaAuthentication();
|
const useAuthentication = useMediaAuthentication();
|
||||||
const [navUserExpanded, setNavUserExpanded] = useState(false);
|
|
||||||
const [hover, setHover] = useState(false);
|
|
||||||
const { hoverProps } = useHover({ onHoverChange: setHover });
|
|
||||||
const { focusWithinProps } = useFocusWithin({
|
|
||||||
onFocusWithinChange: (isFocused) => {
|
|
||||||
setHover(isFocused);
|
|
||||||
if (!isFocused) setNavUserExpanded(false);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const { isCallActive, activeCallRoomId } = useCallState();
|
const { isCallActive, activeCallRoomId } = useCallState();
|
||||||
const isActiveCall = isCallActive && activeCallRoomId === room.roomId;
|
const isActiveCall = isCallActive && activeCallRoomId === room.roomId;
|
||||||
const userId = callMembership.sender ?? '';
|
const userId = callMembership.sender ?? '';
|
||||||
|
|
@ -49,117 +29,32 @@ export function RoomNavUser({ room, callMembership }: RoomNavUserProps) {
|
||||||
const isCallParticipant = isActiveCall && userId !== mx.getUserId();
|
const isCallParticipant = isActiveCall && userId !== mx.getUserId();
|
||||||
|
|
||||||
const handleNavUserClick = () => {
|
const handleNavUserClick = () => {
|
||||||
if (isCallParticipant) {
|
|
||||||
setNavUserExpanded((prev) => !prev);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClickUser = () => {
|
|
||||||
openProfileViewer(userId, room.roomId);
|
openProfileViewer(userId, room.roomId);
|
||||||
};
|
};
|
||||||
|
|
||||||
// PLACEHOLDER
|
const ariaLabel = isCallParticipant ? `Call Participant: ${getName}` : getName;
|
||||||
const [userMuted, setUserMuted] = useState(false);
|
|
||||||
const handleToggleMute = () => {
|
|
||||||
setUserMuted(!userMuted);
|
|
||||||
};
|
|
||||||
|
|
||||||
const optionsVisible = (hover || userMuted || navUserExpanded) && isCallParticipant && false; // Disable until individual volume control and mute have been added
|
|
||||||
const ariaLabel = isCallParticipant
|
|
||||||
? `Call Participant: ${getName}${userMuted ? ', Muted' : ''}`
|
|
||||||
: getName;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NavItem
|
<NavItem variant="Background" radii="400">
|
||||||
tabIndex={0}
|
<NavButton onClick={handleNavUserClick} aria-label={ariaLabel}>
|
||||||
variant="Background"
|
<NavItemContent>
|
||||||
radii="400"
|
<Box direction="Column" grow="Yes" gap="200" justifyContent="Stretch">
|
||||||
style={{ paddingTop: config.space.S200, paddingBottom: config.space.S200 }}
|
<Box as="span" alignItems="Center" gap="200">
|
||||||
{...hoverProps}
|
<Avatar size="200">
|
||||||
{...focusWithinProps}
|
<UserAvatar
|
||||||
aria-label={ariaLabel}
|
userId={userId}
|
||||||
>
|
src={avatarUrl ?? undefined}
|
||||||
<NavItemContent onClick={handleNavUserClick}>
|
alt={getName}
|
||||||
<Box direction="Column" grow="Yes" gap="200" justifyContent="Stretch">
|
renderFallback={() => <Icon size="50" src={Icons.User} filled />}
|
||||||
<Box as="span" alignItems="Center" gap="200">
|
/>
|
||||||
<Avatar size="200">
|
</Avatar>
|
||||||
<UserAvatar
|
<Text size="B400" priority="300" truncate>
|
||||||
userId={userId}
|
{getName}
|
||||||
src={avatarUrl ?? undefined}
|
</Text>
|
||||||
alt={getName}
|
|
||||||
renderFallback={() => <Icon size="50" src={Icons.User} filled />}
|
|
||||||
/>
|
|
||||||
</Avatar>
|
|
||||||
<Text
|
|
||||||
size="B400"
|
|
||||||
priority="300"
|
|
||||||
// Set priority based on if talking
|
|
||||||
truncate
|
|
||||||
>
|
|
||||||
{getName}
|
|
||||||
</Text>
|
|
||||||
</Box>
|
|
||||||
{navUserExpanded && (
|
|
||||||
<Box as="span" grow="Yes" alignItems="Center" gap="200">
|
|
||||||
{/* Slider here, when implemented into folds */}
|
|
||||||
<Text>---- THIS IS A SLIDER ---</Text>
|
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
</Box>
|
||||||
</Box>
|
</NavItemContent>
|
||||||
</NavItemContent>
|
</NavButton>
|
||||||
{optionsVisible && (
|
|
||||||
<NavItemOptions direction="Column" justifyContent="SpaceBetween">
|
|
||||||
<TooltipProvider
|
|
||||||
position="Bottom"
|
|
||||||
offset={4}
|
|
||||||
tooltip={
|
|
||||||
<Tooltip>
|
|
||||||
<Text>{userMuted ? 'Unmute' : 'Mute'}</Text>
|
|
||||||
</Tooltip>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{(triggerRef) => (
|
|
||||||
<IconButton
|
|
||||||
ref={triggerRef}
|
|
||||||
onClick={handleToggleMute}
|
|
||||||
aria-pressed={userMuted}
|
|
||||||
aria-label={userMuted ? `Unmute ${getName}` : `Mute ${getName}`}
|
|
||||||
variant={userMuted ? 'Critical' : 'Background'}
|
|
||||||
fill="None"
|
|
||||||
size="300"
|
|
||||||
radii="300"
|
|
||||||
>
|
|
||||||
<Icon size="50" src={userMuted ? Icons.VolumeMute : Icons.VolumeHigh} />
|
|
||||||
</IconButton>
|
|
||||||
)}
|
|
||||||
</TooltipProvider>
|
|
||||||
{navUserExpanded && (
|
|
||||||
<TooltipProvider
|
|
||||||
position="Bottom"
|
|
||||||
offset={4}
|
|
||||||
tooltip={
|
|
||||||
<Tooltip>
|
|
||||||
<Text>View Profile</Text>
|
|
||||||
</Tooltip>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{(triggerRef) => (
|
|
||||||
<IconButton
|
|
||||||
ref={triggerRef}
|
|
||||||
onClick={handleClickUser}
|
|
||||||
aria-label="View Profile"
|
|
||||||
variant="Background"
|
|
||||||
fill="None"
|
|
||||||
size="300"
|
|
||||||
radii="300"
|
|
||||||
>
|
|
||||||
<Icon size="50" src={Icons.User} />
|
|
||||||
</IconButton>
|
|
||||||
)}
|
|
||||||
</TooltipProvider>
|
|
||||||
)}
|
|
||||||
</NavItemOptions>
|
|
||||||
)}
|
|
||||||
</NavItem>
|
</NavItem>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue