Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

RoomContextMenu.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // @flow
  2. import React, { useCallback } from 'react';
  3. import { useTranslation } from 'react-i18next';
  4. import { useDispatch, useSelector } from 'react-redux';
  5. import { createBreakoutRoomsEvent, sendAnalytics } from '../../../analytics';
  6. import { ContextMenu, ContextMenuItemGroup } from '../../../base/components';
  7. import {
  8. IconClose,
  9. IconRingGroup
  10. } from '../../../base/icons';
  11. import { isLocalParticipantModerator } from '../../../base/participants';
  12. import { showOverflowDrawer } from '../../../toolbox/functions.web';
  13. import { closeBreakoutRoom, moveToRoom, removeBreakoutRoom } from '../../actions';
  14. type Props = {
  15. /**
  16. * Room reference.
  17. */
  18. entity: Object,
  19. /**
  20. * Target elements against which positioning calculations are made.
  21. */
  22. offsetTarget: HTMLElement,
  23. /**
  24. * Callback for the mouse entering the component.
  25. */
  26. onEnter: Function,
  27. /**
  28. * Callback for the mouse leaving the component.
  29. */
  30. onLeave: Function,
  31. /**
  32. * Callback for making a selection in the menu.
  33. */
  34. onSelect: Function
  35. };
  36. export const RoomContextMenu = ({
  37. entity: room,
  38. offsetTarget,
  39. onEnter,
  40. onLeave,
  41. onSelect
  42. }: Props) => {
  43. const dispatch = useDispatch();
  44. const { t } = useTranslation();
  45. const isLocalModerator = useSelector(isLocalParticipantModerator);
  46. const _overflowDrawer = useSelector(showOverflowDrawer);
  47. const onJoinRoom = useCallback(() => {
  48. sendAnalytics(createBreakoutRoomsEvent('join'));
  49. dispatch(moveToRoom(room.id));
  50. }, [ dispatch, room ]);
  51. const onRemoveBreakoutRoom = useCallback(() => {
  52. dispatch(removeBreakoutRoom(room.jid));
  53. }, [ dispatch, room ]);
  54. const onCloseBreakoutRoom = useCallback(() => {
  55. dispatch(closeBreakoutRoom(room.id));
  56. }, [ dispatch, room ]);
  57. const isRoomEmpty = !(room?.participants && Object.keys(room.participants).length > 0);
  58. const actions = [
  59. _overflowDrawer ? {
  60. accessibilityLabel: t('breakoutRooms.actions.join'),
  61. icon: IconRingGroup,
  62. onClick: onJoinRoom,
  63. text: t('breakoutRooms.actions.join')
  64. } : null,
  65. !room?.isMainRoom && isLocalModerator ? {
  66. accessibilityLabel: isRoomEmpty ? t('breakoutRooms.actions.remove') : t('breakoutRooms.actions.close'),
  67. icon: IconClose,
  68. id: isRoomEmpty ? `remove-room-${room?.id}` : `close-room-${room?.id}`,
  69. onClick: isRoomEmpty ? onRemoveBreakoutRoom : onCloseBreakoutRoom,
  70. text: isRoomEmpty ? t('breakoutRooms.actions.remove') : t('breakoutRooms.actions.close')
  71. } : null
  72. ].filter(Boolean);
  73. const lowerMenu = useCallback(() => onSelect(true));
  74. return (
  75. <ContextMenu
  76. entity = { room }
  77. isDrawerOpen = { room }
  78. offsetTarget = { offsetTarget }
  79. onClick = { lowerMenu }
  80. onDrawerClose = { onSelect }
  81. onMouseEnter = { onEnter }
  82. onMouseLeave = { onLeave }>
  83. <ContextMenuItemGroup actions = { actions } />
  84. </ContextMenu>
  85. );
  86. };