2020-04-01 07:47:51 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
/* eslint-disable react/jsx-no-bind */
|
|
|
|
|
2020-04-01 07:47:51 +00:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
|
|
|
|
import { translate } from '../../../../base/i18n';
|
|
|
|
import { Icon, IconCheck, IconCopy } from '../../../../base/icons';
|
2022-10-06 08:11:06 +00:00
|
|
|
import { copyText } from '../../../../base/util/copyText.web';
|
2020-04-01 07:47:51 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current known URL for a live stream in progress.
|
|
|
|
*/
|
|
|
|
liveStreamViewURL: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Section of the {@code AddPeopleDialog} that renders the
|
|
|
|
* live streaming url, allowing a copy action.
|
|
|
|
*
|
|
|
|
* @returns {React$Element<any>}
|
|
|
|
*/
|
|
|
|
function LiveStreamSection({ liveStreamViewURL, t }: Props) {
|
|
|
|
const [ isClicked, setIsClicked ] = useState(false);
|
|
|
|
const [ isHovered, setIsHovered ] = useState(false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click handler for the element.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2021-03-03 21:04:00 +00:00
|
|
|
async function onClick() {
|
2020-04-01 07:47:51 +00:00
|
|
|
setIsHovered(false);
|
2021-03-03 21:04:00 +00:00
|
|
|
|
2021-03-03 22:25:19 +00:00
|
|
|
const isCopied = await copyText(liveStreamViewURL);
|
2021-03-03 21:04:00 +00:00
|
|
|
|
|
|
|
if (isCopied) {
|
2020-04-01 07:47:51 +00:00
|
|
|
setIsClicked(true);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
setIsClicked(false);
|
|
|
|
}, 2500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hover handler for the element.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function onHoverIn() {
|
|
|
|
if (!isClicked) {
|
|
|
|
setIsHovered(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hover handler for the element.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function onHoverOut() {
|
|
|
|
setIsHovered(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the content of the link based on the state.
|
|
|
|
*
|
|
|
|
* @returns {React$Element<any>}
|
|
|
|
*/
|
|
|
|
function renderLinkContent() {
|
|
|
|
if (isClicked) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className = 'invite-more-dialog stream-text selected'>
|
|
|
|
{t('addPeople.linkCopied')}
|
|
|
|
</div>
|
|
|
|
<Icon src = { IconCheck } />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className = 'invite-more-dialog stream-text'>
|
|
|
|
{isHovered ? t('addPeople.copyStream') : liveStreamViewURL}
|
|
|
|
</div>
|
|
|
|
<Icon src = { IconCopy } />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>{t('addPeople.shareStream')}</span>
|
|
|
|
<div
|
|
|
|
className = { `invite-more-dialog stream${isClicked ? ' clicked' : ''}` }
|
|
|
|
onClick = { onClick }
|
|
|
|
onMouseOut = { onHoverOut }
|
|
|
|
onMouseOver = { onHoverIn }>
|
|
|
|
{ renderLinkContent() }
|
|
|
|
</div>
|
|
|
|
<div className = 'invite-more-dialog separator' />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(LiveStreamSection);
|