2022-09-27 07:10:28 +00:00
|
|
|
import React, { useCallback, useRef, useState } from 'react';
|
2021-04-21 13:48:05 +00:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2022-03-03 17:29:38 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
2022-09-13 07:36:00 +00:00
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2022-11-08 10:24:32 +00:00
|
|
|
import { IconDotsHorizontal, IconMessage, IconUserDeleted } from '../../../base/icons/svg';
|
2022-08-25 11:35:19 +00:00
|
|
|
import { hasRaisedHand } from '../../../base/participants/functions';
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IParticipant } from '../../../base/participants/types';
|
2022-07-27 09:33:50 +00:00
|
|
|
import Button from '../../../base/ui/components/web/Button';
|
2022-10-06 10:09:40 +00:00
|
|
|
import ContextMenu from '../../../base/ui/components/web/ContextMenu';
|
|
|
|
import ContextMenuItemGroup from '../../../base/ui/components/web/ContextMenuItemGroup';
|
2022-11-09 12:45:55 +00:00
|
|
|
import { BUTTON_TYPES } from '../../../base/ui/constants.web';
|
2022-03-03 17:29:38 +00:00
|
|
|
import { showLobbyChatButton } from '../../../lobby/functions';
|
2021-06-24 13:26:55 +00:00
|
|
|
import { ACTION_TRIGGER, MEDIA_STATE } from '../../constants';
|
2021-09-10 11:05:16 +00:00
|
|
|
import { useLobbyActions } from '../../hooks';
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
import ParticipantItem from './ParticipantItem';
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2022-11-03 08:35:51 +00:00
|
|
|
interface IProps {
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2021-09-10 11:05:16 +00:00
|
|
|
/**
|
2022-08-25 11:35:19 +00:00
|
|
|
* Callback used to open a drawer with admit/reject actions.
|
2021-09-10 11:05:16 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
openDrawerForParticipant: Function;
|
2021-09-10 11:05:16 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-25 11:35:19 +00:00
|
|
|
* If an overflow drawer should be displayed.
|
2021-09-10 11:05:16 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
overflowDrawer: boolean;
|
2021-09-10 11:05:16 +00:00
|
|
|
|
2021-04-21 13:48:05 +00:00
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Participant reference.
|
2021-04-21 13:48:05 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
participant: IParticipant;
|
2022-11-03 08:35:51 +00:00
|
|
|
}
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2022-11-15 07:50:22 +00:00
|
|
|
const useStyles = makeStyles()(theme => {
|
2021-10-22 13:23:52 +00:00
|
|
|
return {
|
|
|
|
button: {
|
2022-09-13 07:36:00 +00:00
|
|
|
marginRight: theme.spacing(2)
|
2022-03-03 17:29:38 +00:00
|
|
|
},
|
|
|
|
moreButton: {
|
|
|
|
paddingRight: '6px',
|
|
|
|
paddingLeft: '6px',
|
2022-09-13 07:36:00 +00:00
|
|
|
marginRight: theme.spacing(2)
|
2022-03-03 17:29:38 +00:00
|
|
|
},
|
|
|
|
contextMenu: {
|
|
|
|
position: 'fixed',
|
|
|
|
top: 'auto',
|
|
|
|
marginRight: '8px'
|
2021-10-22 13:23:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2021-09-10 11:05:16 +00:00
|
|
|
export const LobbyParticipantItem = ({
|
|
|
|
overflowDrawer,
|
|
|
|
participant: p,
|
|
|
|
openDrawerForParticipant
|
2022-11-03 08:35:51 +00:00
|
|
|
}: IProps) => {
|
2021-09-10 11:05:16 +00:00
|
|
|
const { id } = p;
|
2022-03-03 17:29:38 +00:00
|
|
|
const [ admit, reject, chat ] = useLobbyActions({ participantID: id });
|
2021-04-21 13:48:05 +00:00
|
|
|
const { t } = useTranslation();
|
2022-03-03 17:29:38 +00:00
|
|
|
const [ isOpen, setIsOpen ] = useState(false);
|
2022-09-13 07:36:00 +00:00
|
|
|
const { classes: styles } = useStyles();
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2022-03-03 17:29:38 +00:00
|
|
|
const showChat = useSelector(showLobbyChatButton(p));
|
|
|
|
|
|
|
|
const moreButtonRef = useRef();
|
|
|
|
|
2022-08-25 11:35:19 +00:00
|
|
|
const openContextMenu = useCallback(() => setIsOpen(true), []);
|
|
|
|
const closeContextMenu = useCallback(() => setIsOpen(false), []);
|
2022-03-03 17:29:38 +00:00
|
|
|
|
|
|
|
const renderAdmitButton = () => (
|
2022-07-27 09:33:50 +00:00
|
|
|
<Button
|
2022-03-03 17:29:38 +00:00
|
|
|
accessibilityLabel = { `${t('lobby.admit')} ${p.name}` }
|
|
|
|
className = { styles.button }
|
2022-08-22 09:40:59 +00:00
|
|
|
labelKey = { 'lobby.admit' }
|
2022-03-03 17:29:38 +00:00
|
|
|
onClick = { admit }
|
2022-07-27 09:33:50 +00:00
|
|
|
size = 'small'
|
|
|
|
testId = { `admit-${id}` } />);
|
2022-03-03 17:29:38 +00:00
|
|
|
|
2021-04-21 13:48:05 +00:00
|
|
|
return (
|
|
|
|
<ParticipantItem
|
2021-06-23 11:23:44 +00:00
|
|
|
actionsTrigger = { ACTION_TRIGGER.PERMANENT }
|
|
|
|
audioMediaState = { MEDIA_STATE.NONE }
|
2021-07-09 12:36:19 +00:00
|
|
|
displayName = { p.name }
|
|
|
|
local = { p.local }
|
2021-09-10 11:05:16 +00:00
|
|
|
openDrawerForParticipant = { openDrawerForParticipant }
|
|
|
|
overflowDrawer = { overflowDrawer }
|
|
|
|
participantID = { id }
|
2021-10-21 09:40:57 +00:00
|
|
|
raisedHand = { hasRaisedHand(p) }
|
2021-09-10 11:05:16 +00:00
|
|
|
videoMediaState = { MEDIA_STATE.NONE }
|
2021-07-09 12:36:19 +00:00
|
|
|
youText = { t('chat.you') }>
|
2022-03-03 17:29:38 +00:00
|
|
|
|
|
|
|
{showChat ? <>
|
|
|
|
{renderAdmitButton()}
|
2022-07-27 09:33:50 +00:00
|
|
|
<Button
|
2022-03-03 17:29:38 +00:00
|
|
|
accessibilityLabel = { `${t('participantsPane.actions.moreModerationActions')} ${p.name}` }
|
|
|
|
className = { styles.moreButton }
|
2022-11-08 10:24:32 +00:00
|
|
|
icon = { IconDotsHorizontal }
|
2022-03-03 17:29:38 +00:00
|
|
|
onClick = { openContextMenu }
|
|
|
|
ref = { moreButtonRef }
|
2022-07-27 09:33:50 +00:00
|
|
|
size = 'small' />
|
2022-03-03 17:29:38 +00:00
|
|
|
<ContextMenu
|
|
|
|
className = { styles.contextMenu }
|
|
|
|
hidden = { !isOpen }
|
|
|
|
offsetTarget = { moreButtonRef.current }
|
|
|
|
onMouseLeave = { closeContextMenu }>
|
|
|
|
<ContextMenuItemGroup
|
|
|
|
actions = { [ {
|
|
|
|
accessibilityLabel: `${t('lobby.chat')} ${p.name}`,
|
|
|
|
onClick: chat,
|
|
|
|
testId: `lobby-chat-${id}`,
|
2022-11-08 10:24:32 +00:00
|
|
|
icon: IconMessage,
|
2022-03-03 17:29:38 +00:00
|
|
|
text: t('lobby.chat')
|
|
|
|
} ] } />
|
|
|
|
<ContextMenuItemGroup
|
|
|
|
actions = { [ {
|
|
|
|
accessibilityLabel: `${t('lobby.reject')} ${p.name}`,
|
|
|
|
onClick: reject,
|
|
|
|
testId: `reject-${id}`,
|
2022-11-08 10:24:32 +00:00
|
|
|
icon: IconUserDeleted,
|
2022-03-03 17:29:38 +00:00
|
|
|
text: t('lobby.reject')
|
|
|
|
} ] } />
|
|
|
|
</ContextMenu>
|
|
|
|
</> : <>
|
2022-07-27 09:33:50 +00:00
|
|
|
<Button
|
2022-03-03 17:29:38 +00:00
|
|
|
accessibilityLabel = { `${t('lobby.reject')} ${p.name}` }
|
|
|
|
className = { styles.button }
|
2022-08-22 09:40:59 +00:00
|
|
|
labelKey = { 'lobby.reject' }
|
2022-03-03 17:29:38 +00:00
|
|
|
onClick = { reject }
|
2022-07-27 09:33:50 +00:00
|
|
|
size = 'small'
|
|
|
|
testId = { `reject-${id}` }
|
|
|
|
type = { BUTTON_TYPES.DESTRUCTIVE } />
|
2022-03-03 17:29:38 +00:00
|
|
|
{renderAdmitButton()}
|
|
|
|
</>
|
|
|
|
}
|
2021-04-21 13:48:05 +00:00
|
|
|
</ParticipantItem>
|
|
|
|
);
|
|
|
|
};
|