You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LiveStreamSection.tsx 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* eslint-disable react/jsx-no-bind */
  2. import React, { useState } from 'react';
  3. import { WithTranslation } from 'react-i18next';
  4. import { translate } from '../../../../base/i18n/functions';
  5. import Icon from '../../../../base/icons/components/Icon';
  6. import { IconCheck, IconCopy } from '../../../../base/icons/svg';
  7. import { copyText } from '../../../../base/util/copyText.web';
  8. interface IProps extends WithTranslation {
  9. /**
  10. * The current known URL for a live stream in progress.
  11. */
  12. liveStreamViewURL: string;
  13. }
  14. /**
  15. * Section of the {@code AddPeopleDialog} that renders the
  16. * live streaming url, allowing a copy action.
  17. *
  18. * @returns {React$Element<any>}
  19. */
  20. function LiveStreamSection({ liveStreamViewURL, t }: IProps) {
  21. const [ isClicked, setIsClicked ] = useState(false);
  22. const [ isHovered, setIsHovered ] = useState(false);
  23. /**
  24. * Click handler for the element.
  25. *
  26. * @returns {void}
  27. */
  28. async function onClick() {
  29. setIsHovered(false);
  30. const isCopied = await copyText(liveStreamViewURL);
  31. if (isCopied) {
  32. setIsClicked(true);
  33. setTimeout(() => {
  34. setIsClicked(false);
  35. }, 2500);
  36. }
  37. }
  38. /**
  39. * Hover handler for the element.
  40. *
  41. * @returns {void}
  42. */
  43. function onHoverIn() {
  44. if (!isClicked) {
  45. setIsHovered(true);
  46. }
  47. }
  48. /**
  49. * Hover handler for the element.
  50. *
  51. * @returns {void}
  52. */
  53. function onHoverOut() {
  54. setIsHovered(false);
  55. }
  56. /**
  57. * Renders the content of the link based on the state.
  58. *
  59. * @returns {React$Element<any>}
  60. */
  61. function renderLinkContent() {
  62. if (isClicked) {
  63. return (
  64. <>
  65. <div className = 'invite-more-dialog stream-text selected'>
  66. {t('addPeople.linkCopied')}
  67. </div>
  68. <Icon src = { IconCheck } />
  69. </>
  70. );
  71. }
  72. return (
  73. <>
  74. <div className = 'invite-more-dialog stream-text'>
  75. {isHovered ? t('addPeople.copyStream') : liveStreamViewURL}
  76. </div>
  77. <Icon src = { IconCopy } />
  78. </>
  79. );
  80. }
  81. return (
  82. <>
  83. <span>{t('addPeople.shareStream')}</span>
  84. <div
  85. className = { `invite-more-dialog stream${isClicked ? ' clicked' : ''}` }
  86. onClick = { onClick }
  87. onMouseOut = { onHoverOut }
  88. onMouseOver = { onHoverIn }>
  89. { renderLinkContent() }
  90. </div>
  91. <div className = 'invite-more-dialog separator' />
  92. </>
  93. );
  94. }
  95. export default translate(LiveStreamSection);