Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CopyMeetingUrl.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { getCurrentConferenceUrl } from '../../../connection';
  4. import { translate } from '../../../i18n';
  5. import { Icon, IconCopy, IconCheck } from '../../../icons';
  6. import { connect } from '../../../redux';
  7. import { copyText, getDecodedURI } from '../../../util';
  8. type Props = {
  9. /**
  10. * The meeting url.
  11. */
  12. url: string,
  13. /**
  14. * Used for translation.
  15. */
  16. t: Function
  17. };
  18. type State = {
  19. /**
  20. * If true it shows the 'copy link' message.
  21. */
  22. showCopyLink: boolean,
  23. /**
  24. * If true it shows the 'link copied' message.
  25. */
  26. showLinkCopied: boolean,
  27. };
  28. const COPY_TIMEOUT = 2000;
  29. /**
  30. * Component used to copy meeting url on prejoin page.
  31. */
  32. class CopyMeetingUrl extends Component<Props, State> {
  33. /**
  34. * Initializes a new {@code Prejoin} instance.
  35. *
  36. * @inheritdoc
  37. */
  38. constructor(props) {
  39. super(props);
  40. this.state = {
  41. showCopyLink: false,
  42. showLinkCopied: false
  43. };
  44. this._copyUrl = this._copyUrl.bind(this);
  45. this._hideCopyLink = this._hideCopyLink.bind(this);
  46. this._hideLinkCopied = this._hideLinkCopied.bind(this);
  47. this._showCopyLink = this._showCopyLink.bind(this);
  48. this._showLinkCopied = this._showLinkCopied.bind(this);
  49. }
  50. _copyUrl: () => void;
  51. /**
  52. * Callback invoked to copy the url to clipboard.
  53. *
  54. * @returns {void}
  55. */
  56. _copyUrl() {
  57. const success = copyText(this.props.url);
  58. if (success) {
  59. this._showLinkCopied();
  60. window.setTimeout(this._hideLinkCopied, COPY_TIMEOUT);
  61. }
  62. }
  63. _hideLinkCopied: () => void;
  64. /**
  65. * Hides the 'Link copied' message.
  66. *
  67. * @private
  68. * @returns {void}
  69. */
  70. _hideLinkCopied() {
  71. this.setState({
  72. showLinkCopied: false
  73. });
  74. }
  75. _hideCopyLink: () => void;
  76. /**
  77. * Hides the 'Copy link' text.
  78. *
  79. * @private
  80. * @returns {void}
  81. */
  82. _hideCopyLink() {
  83. this.setState({
  84. showCopyLink: false,
  85. showLinkCopied: false
  86. });
  87. }
  88. _showCopyLink: () => void;
  89. /**
  90. * Shows the dark 'Copy link' text on hover.
  91. *
  92. * @private
  93. * @returns {void}
  94. */
  95. _showCopyLink() {
  96. this.setState({
  97. showCopyLink: true,
  98. showLinkCopied: false
  99. });
  100. }
  101. _showLinkCopied: () => void;
  102. /**
  103. * Shows the green 'Link copied' message.
  104. *
  105. * @private
  106. * @returns {void}
  107. */
  108. _showLinkCopied() {
  109. this.setState({
  110. showLinkCopied: true,
  111. showCopyLink: false
  112. });
  113. }
  114. /**
  115. * Implements React's {@link Component#render()}.
  116. *
  117. * @inheritdoc
  118. * @returns {ReactElement}
  119. */
  120. render() {
  121. const { showCopyLink, showLinkCopied } = this.state;
  122. const { url, t } = this.props;
  123. const { _copyUrl, _showCopyLink, _hideCopyLink } = this;
  124. const src = showLinkCopied ? IconCheck : IconCopy;
  125. return (
  126. <div
  127. className = 'copy-meeting'
  128. onMouseEnter = { _showCopyLink }
  129. onMouseLeave = { _hideCopyLink }>
  130. <div
  131. className = { `url ${showLinkCopied ? 'done' : ''}` }
  132. onClick = { _copyUrl } >
  133. <div className = 'copy-meeting-text'>
  134. { !showCopyLink && !showLinkCopied && getDecodedURI(url) }
  135. { showCopyLink && t('prejoin.copyAndShare') }
  136. { showLinkCopied && t('prejoin.linkCopied') }
  137. </div>
  138. <Icon
  139. onClick = { _copyUrl }
  140. size = { 24 }
  141. src = { src } />
  142. </div>
  143. </div>
  144. );
  145. }
  146. }
  147. /**
  148. * Maps (parts of) the redux state to the React {@code Component} props.
  149. *
  150. * @param {Object} state - The redux state.
  151. * @returns {Object}
  152. */
  153. function mapStateToProps(state) {
  154. return {
  155. url: getCurrentConferenceUrl(state)
  156. };
  157. }
  158. export default connect(mapStateToProps)(translate(CopyMeetingUrl));