// @flow /* eslint-disable react/jsx-no-bind */ import React, { useState } from 'react'; import { translate } from '../../../../base/i18n'; import { Icon, IconCheck, IconCopy } from '../../../../base/icons'; import { copyText } from '../../../../base/util/copyText.web'; 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} */ function LiveStreamSection({ liveStreamViewURL, t }: Props) { const [ isClicked, setIsClicked ] = useState(false); const [ isHovered, setIsHovered ] = useState(false); /** * Click handler for the element. * * @returns {void} */ async function onClick() { setIsHovered(false); const isCopied = await copyText(liveStreamViewURL); if (isCopied) { 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} */ function renderLinkContent() { if (isClicked) { return ( <>
{t('addPeople.linkCopied')}
); } return ( <>
{isHovered ? t('addPeople.copyStream') : liveStreamViewURL}
); } return ( <> {t('addPeople.shareStream')}
{ renderLinkContent() }
); } export default translate(LiveStreamSection);