import {useEffect, useState} from 'react'; import {type PresentationAndId} from '../../functions/src/presentation'; import RoundButton from './toolbar/RoundButton'; export default function Shares({ presentation, slideIndex, }: { readonly presentation: PresentationAndId; readonly slideIndex: number; }) { // TODO: should this parse window.location for the host? const shareUrl = `https://slidr.app/v/${presentation?.id ?? ''}?slide=${ slideIndex + 1 }`; const tweetText = presentation.data === undefined ? '' : `${ presentation.data.title.length > 0 ? presentation?.data.title : 'presentation' }${ presentation.data.username.length > 0 ? ' by ' + presentation.data.username : '' }${ presentation.data.twitterHandle.length > 0 ? ' ' + presentation.data.twitterHandle : '' } ${shareUrl}`; const [copied, setCopied] = useState(false); useEffect(() => { if (!copied) { return; } let handle: NodeJS.Timeout | undefined; handle = setTimeout(() => { handle = undefined; setCopied(false); }, 2000); return () => { if (handle !== undefined) { clearTimeout(handle); } }; }, [copied]); return (
{ event.preventDefault(); void window.navigator.clipboard.writeText(shareUrl); setCopied(true); }} />
); }