您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

LiveStreamSection.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. function onClick() {
  31. setIsHovered(false);
  32. if (copyText(liveStreamViewURL)) {
  33. setIsClicked(true);
  34. setTimeout(() => {
  35. setIsClicked(false);
  36. }, 2500);
  37. }
  38. }
  39. /**
  40. * Hover handler for the element.
  41. *
  42. * @returns {void}
  43. */
  44. function onHoverIn() {
  45. if (!isClicked) {
  46. setIsHovered(true);
  47. }
  48. }
  49. /**
  50. * Hover handler for the element.
  51. *
  52. * @returns {void}
  53. */
  54. function onHoverOut() {
  55. setIsHovered(false);
  56. }
  57. /**
  58. * Renders the content of the link based on the state.
  59. *
  60. * @returns {React$Element<any>}
  61. */
  62. function renderLinkContent() {
  63. if (isClicked) {
  64. return (
  65. <>
  66. <div className = 'invite-more-dialog stream-text selected'>
  67. {t('addPeople.linkCopied')}
  68. </div>
  69. <Icon src = { IconCheck } />
  70. </>
  71. );
  72. }
  73. return (
  74. <>
  75. <div className = 'invite-more-dialog stream-text'>
  76. {isHovered ? t('addPeople.copyStream') : liveStreamViewURL}
  77. </div>
  78. <Icon src = { IconCopy } />
  79. </>
  80. );
  81. }
  82. return (
  83. <>
  84. <span>{t('addPeople.shareStream')}</span>
  85. <div
  86. className = { `invite-more-dialog stream${isClicked ? ' clicked' : ''}` }
  87. onClick = { onClick }
  88. onMouseOut = { onHoverOut }
  89. onMouseOver = { onHoverIn }>
  90. { renderLinkContent() }
  91. </div>
  92. <div className = 'invite-more-dialog separator' />
  93. </>
  94. );
  95. }
  96. export default translate(LiveStreamSection);