2022-08-25 11:35:19 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
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-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2022-03-03 17:29:38 +00:00
|
|
|
import { ContextMenu, ContextMenuItemGroup } from '../../../base/components';
|
2022-08-25 11:35:19 +00:00
|
|
|
import { IconChat, IconCloseCircle, IconHorizontalPoints } from '../../../base/icons/svg/index';
|
|
|
|
import { hasRaisedHand } from '../../../base/participants/functions';
|
|
|
|
import { Participant } from '../../../base/participants/reducer';
|
2022-07-27 09:33:50 +00:00
|
|
|
import Button from '../../../base/ui/components/web/Button';
|
2022-08-17 07:14:25 +00:00
|
|
|
import { BUTTON_TYPES } from '../../../base/ui/constants';
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2022-03-03 17:29:38 +00:00
|
|
|
import { showLobbyChatButton } from '../../../lobby/functions';
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-06-24 13:26:55 +00:00
|
|
|
import { ACTION_TRIGGER, MEDIA_STATE } from '../../constants';
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-09-10 11:05:16 +00:00
|
|
|
import { useLobbyActions } from '../../hooks';
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
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
|
|
|
/**
|
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-08-25 11:35:19 +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-08-25 11:35:19 +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-08-25 11:35:19 +00:00
|
|
|
participant: Participant
|
2021-04-21 13:48:05 +00:00
|
|
|
};
|
|
|
|
|
2022-08-25 11:35:19 +00:00
|
|
|
const useStyles = makeStyles((theme: any) => {
|
2021-10-22 13:23:52 +00:00
|
|
|
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();
|
|
|
|
|
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-07-27 09:33:50 +00:00
|
|
|
icon = { IconHorizontalPoints }
|
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}`,
|
|
|
|
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>
|
|
|
|
</> : <>
|
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>
|
|
|
|
);
|
|
|
|
};
|