import React, { useRef } from "react"; import { copyTextToSystemClipboard } from "../../clipboard"; import { Dialog } from "../../components/Dialog"; import { clipboard, start, stop, share, shareIOS, shareWindows, } from "../../components/icons"; import { ToolButton } from "../../components/ToolButton"; import { t } from "../../i18n"; import "./RoomDialog.scss"; import Stack from "../../components/Stack"; import { AppState } from "../../types"; import { trackEvent } from "../../analytics"; import { getFrame } from "../../utils"; const getShareIcon = () => { const navigator = window.navigator as any; const isAppleBrowser = /Apple/.test(navigator.vendor); const isWindowsBrowser = navigator.appVersion.indexOf("Win") !== -1; if (isAppleBrowser) { return shareIOS; } else if (isWindowsBrowser) { return shareWindows; } return share; }; const RoomDialog = ({ handleClose, activeRoomLink, username, onUsernameChange, onRoomCreate, onRoomDestroy, setErrorMessage, theme, }: { handleClose: () => void; activeRoomLink: string; username: string; onUsernameChange: (username: string) => void; onRoomCreate: () => void; onRoomDestroy: () => void; setErrorMessage: (message: string) => void; theme: AppState["theme"]; }) => { const roomLinkInput = useRef(null); const copyRoomLink = async () => { try { await copyTextToSystemClipboard(activeRoomLink); } catch (error: any) { setErrorMessage(error.message); } if (roomLinkInput.current) { roomLinkInput.current.select(); } }; const shareRoomLink = async () => { try { await navigator.share({ title: t("roomDialog.shareTitle"), text: t("roomDialog.shareTitle"), url: activeRoomLink, }); } catch (error: any) { // Just ignore. } }; const selectInput = (event: React.MouseEvent) => { if (event.target !== document.activeElement) { event.preventDefault(); (event.target as HTMLInputElement).select(); } }; const renderRoomDialog = () => { return (
{!activeRoomLink && ( <>

{t("roomDialog.desc_intro")}

{`🔒 ${t("roomDialog.desc_privacy")}`}

{ trackEvent("share", "room creation", `ui (${getFrame()})`); onRoomCreate(); }} />
)} {activeRoomLink && ( <>

{t("roomDialog.desc_inProgressIntro")}

{t("roomDialog.desc_shareLink")}

{"share" in navigator ? ( ) : null}
onUsernameChange(event.target.value)} onKeyPress={(event) => event.key === "Enter" && handleClose()} />

{" "} {t("roomDialog.desc_privacy")}

{t("roomDialog.desc_exitSession")}

{ trackEvent("share", "room closed"); onRoomDestroy(); }} />
)}
); }; return ( {renderRoomDialog()} ); }; export default RoomDialog;