2021-04-21 13:48:05 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-10-22 13:23:52 +00:00
|
|
|
import { makeStyles } from '@material-ui/styles';
|
2022-03-03 17:29:38 +00:00
|
|
|
import React, { useCallback, useState, useRef } 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';
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2022-03-03 17:29:38 +00:00
|
|
|
import { ContextMenu, ContextMenuItemGroup } from '../../../base/components';
|
|
|
|
import { Icon, IconChat, IconCloseCircle, IconHorizontalPoints } from '../../../base/icons';
|
2021-10-21 09:40:57 +00:00
|
|
|
import { hasRaisedHand } from '../../../base/participants';
|
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-10-22 13:23:52 +00:00
|
|
|
import LobbyParticipantQuickAction from './LobbyParticipantQuickAction';
|
2021-07-09 12:36:19 +00:00
|
|
|
import ParticipantItem from './ParticipantItem';
|
2021-04-21 13:48:05 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
2021-09-10 11:05:16 +00:00
|
|
|
/**
|
|
|
|
* If an overflow drawer should be displayed.
|
|
|
|
*/
|
|
|
|
overflowDrawer: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback used to open a drawer with admit/reject actions.
|
|
|
|
*/
|
|
|
|
openDrawerForParticipant: Function,
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
participant: Object
|
|
|
|
};
|
|
|
|
|
2021-10-22 13:23:52 +00:00
|
|
|
const useStyles = makeStyles(theme => {
|
|
|
|
return {
|
|
|
|
button: {
|
|
|
|
marginRight: `${theme.spacing(2)}px`
|
2022-03-03 17:29:38 +00:00
|
|
|
},
|
|
|
|
moreButton: {
|
|
|
|
paddingRight: '6px',
|
|
|
|
paddingLeft: '6px',
|
|
|
|
marginRight: `${theme.spacing(2)}px`
|
|
|
|
},
|
|
|
|
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
|
|
|
|
}: Props) => {
|
|
|
|
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);
|
2021-10-22 13:23:52 +00:00
|
|
|
const 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();
|
|
|
|
|
|
|
|
const openContextMenu = useCallback(() => setIsOpen(true));
|
|
|
|
const closeContextMenu = useCallback(() => setIsOpen(false));
|
|
|
|
|
|
|
|
const renderAdmitButton = () => (
|
|
|
|
<LobbyParticipantQuickAction
|
|
|
|
accessibilityLabel = { `${t('lobby.admit')} ${p.name}` }
|
|
|
|
className = { styles.button }
|
|
|
|
onClick = { admit }
|
|
|
|
testId = { `admit-${id}` }>
|
|
|
|
{t('lobby.admit')}
|
|
|
|
</LobbyParticipantQuickAction>);
|
|
|
|
|
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()}
|
|
|
|
<LobbyParticipantQuickAction
|
|
|
|
accessibilityLabel = { `${t('participantsPane.actions.moreModerationActions')} ${p.name}` }
|
|
|
|
className = { styles.moreButton }
|
|
|
|
onClick = { openContextMenu }
|
|
|
|
ref = { moreButtonRef }
|
|
|
|
secondary = { true }>
|
|
|
|
<Icon src = { IconHorizontalPoints } />
|
|
|
|
</LobbyParticipantQuickAction>
|
|
|
|
<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}`,
|
|
|
|
icon: IconChat,
|
|
|
|
text: t('lobby.chat')
|
|
|
|
} ] } />
|
|
|
|
<ContextMenuItemGroup
|
|
|
|
actions = { [ {
|
|
|
|
accessibilityLabel: `${t('lobby.reject')} ${p.name}`,
|
|
|
|
onClick: reject,
|
|
|
|
testId: `reject-${id}`,
|
|
|
|
icon: IconCloseCircle,
|
|
|
|
text: t('lobby.reject')
|
|
|
|
} ] } />
|
|
|
|
</ContextMenu>
|
|
|
|
</> : <>
|
|
|
|
<LobbyParticipantQuickAction
|
|
|
|
accessibilityLabel = { `${t('lobby.reject')} ${p.name}` }
|
|
|
|
className = { styles.button }
|
|
|
|
onClick = { reject }
|
|
|
|
secondary = { true }
|
|
|
|
testId = { `reject-${id}` }>
|
|
|
|
{t('lobby.reject') }
|
|
|
|
</LobbyParticipantQuickAction>
|
|
|
|
{renderAdmitButton()}
|
|
|
|
</>
|
|
|
|
}
|
2021-04-21 13:48:05 +00:00
|
|
|
</ParticipantItem>
|
|
|
|
);
|
|
|
|
};
|