import React, { useState, useEffect, useRef } from "react"; import { ToolButton } from "./ToolButton"; import { t } from "../i18n"; import useIsMobile from "../is-mobile"; import { users, clipboard, start, stop } from "./icons"; import "./RoomDialog.scss"; import { copyTextToSystemClipboard } from "../clipboard"; import { Dialog } from "./Dialog"; import { AppState } from "../types"; function RoomModal({ activeRoomLink, onRoomCreate, onRoomDestroy, }: { activeRoomLink: string; onRoomCreate: () => void; onRoomDestroy: () => void; }) { const roomLinkInput = useRef(null); function copyRoomLink() { copyTextToSystemClipboard(activeRoomLink); if (roomLinkInput.current) { roomLinkInput.current.select(); } } function selectInput(event: React.MouseEvent) { if (event.target !== document.activeElement) { event.preventDefault(); (event.target as HTMLInputElement).select(); } } return (
{!activeRoomLink && ( <>

{t("roomDialog.desc_intro")}

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

{t("roomDialog.desc_start")}

)} {activeRoomLink && ( <>

{t("roomDialog.desc_inProgressIntro")}

{t("roomDialog.desc_shareLink")}

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

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

{t("roomDialog.desc_exitSession")}

)}
); } export function RoomDialog({ isCollaborating, collaboratorCount, onRoomCreate, onRoomDestroy, }: { isCollaborating: AppState["isCollaborating"]; collaboratorCount: number; onRoomCreate: () => void; onRoomDestroy: () => void; }) { const [modalIsShown, setModalIsShown] = useState(false); const [activeRoomLink, setActiveRoomLink] = useState(""); const triggerButton = useRef(null); const handleClose = React.useCallback(() => { setModalIsShown(false); triggerButton.current?.focus(); }, []); useEffect(() => { setActiveRoomLink(isCollaborating ? window.location.href : ""); }, [isCollaborating]); return ( <> setModalIsShown(true)} icon={users} type="button" title={t("buttons.roomDialog")} aria-label={t("buttons.roomDialog")} showAriaLabel={useIsMobile()} ref={triggerButton} > {collaboratorCount > 0 && (
{collaboratorCount}
)}
{modalIsShown && ( )} ); }