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.js 2.6KB

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