Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

PrivateMessageButton.tsx 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import React, { useCallback } from 'react';
  2. import { useDispatch, useSelector } from 'react-redux';
  3. import { makeStyles } from 'tss-react/mui';
  4. import { IReduxState } from '../../../app/types';
  5. import { CHAT_ENABLED } from '../../../base/flags/constants';
  6. import { getFeatureFlag } from '../../../base/flags/functions';
  7. import { IconReply } from '../../../base/icons/svg';
  8. import { getParticipantById } from '../../../base/participants/functions';
  9. import Button from '../../../base/ui/components/web/Button';
  10. import { BUTTON_TYPES } from '../../../base/ui/constants.any';
  11. import { handleLobbyChatInitialized, openChat } from '../../actions.web';
  12. export interface IProps {
  13. /**
  14. * True if the message is a lobby chat message.
  15. */
  16. isLobbyMessage: boolean;
  17. /**
  18. * The ID of the participant that the message is to be sent.
  19. */
  20. participantID: string;
  21. /**
  22. * Whether the button should be visible or not.
  23. */
  24. visible?: boolean;
  25. }
  26. const useStyles = makeStyles()(theme => {
  27. return {
  28. replyButton: {
  29. padding: '2px',
  30. '&:hover': {
  31. backgroundColor: theme.palette.action03
  32. }
  33. }
  34. };
  35. });
  36. const PrivateMessageButton = ({ participantID, isLobbyMessage, visible }: IProps) => {
  37. const { classes } = useStyles();
  38. const dispatch = useDispatch();
  39. const participant = useSelector((state: IReduxState) => getParticipantById(state, participantID));
  40. const isVisible = useSelector((state: IReduxState) => getFeatureFlag(state, CHAT_ENABLED, true)) ?? visible;
  41. const handleClick = useCallback(() => {
  42. if (isLobbyMessage) {
  43. dispatch(handleLobbyChatInitialized(participantID));
  44. } else {
  45. dispatch(openChat(participant));
  46. }
  47. }, []);
  48. if (!isVisible) {
  49. return null;
  50. }
  51. return (
  52. <Button
  53. accessibilityLabel = 'toolbar.accessibilityLabel.privateMessage'
  54. className = { classes.replyButton }
  55. icon = { IconReply }
  56. onClick = { handleClick }
  57. type = { BUTTON_TYPES.TERTIARY } />
  58. );
  59. };
  60. export default PrivateMessageButton;