2020-03-11 19:42:18 +01:00
|
|
|
|
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";
|
2020-03-13 15:32:47 -04:00
|
|
|
|
|
|
|
|
|
import "./RoomDialog.scss";
|
2020-03-11 19:42:18 +01:00
|
|
|
|
import { copyTextToSystemClipboard } from "../clipboard";
|
2020-03-13 15:32:47 -04:00
|
|
|
|
import { Dialog } from "./Dialog";
|
2020-03-11 22:48:27 +01:00
|
|
|
|
import { AppState } from "../types";
|
2020-03-11 19:42:18 +01:00
|
|
|
|
|
|
|
|
|
function RoomModal({
|
|
|
|
|
activeRoomLink,
|
2020-04-07 14:02:42 +01:00
|
|
|
|
username,
|
|
|
|
|
onUsernameChange,
|
2020-03-11 19:42:18 +01:00
|
|
|
|
onRoomCreate,
|
|
|
|
|
onRoomDestroy,
|
|
|
|
|
}: {
|
|
|
|
|
activeRoomLink: string;
|
2020-04-07 14:02:42 +01:00
|
|
|
|
username: string;
|
|
|
|
|
onUsernameChange: (username: string) => void;
|
2020-03-11 19:42:18 +01:00
|
|
|
|
onRoomCreate: () => void;
|
|
|
|
|
onRoomDestroy: () => void;
|
|
|
|
|
}) {
|
|
|
|
|
const roomLinkInput = useRef<HTMLInputElement>(null);
|
2020-04-07 14:02:42 +01:00
|
|
|
|
|
2020-03-11 19:42:18 +01:00
|
|
|
|
function copyRoomLink() {
|
|
|
|
|
copyTextToSystemClipboard(activeRoomLink);
|
|
|
|
|
if (roomLinkInput.current) {
|
|
|
|
|
roomLinkInput.current.select();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function selectInput(event: React.MouseEvent<HTMLInputElement>) {
|
|
|
|
|
if (event.target !== document.activeElement) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
(event.target as HTMLInputElement).select();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="RoomDialog-modal">
|
2020-03-13 15:32:47 -04:00
|
|
|
|
{!activeRoomLink && (
|
|
|
|
|
<>
|
|
|
|
|
<p>{t("roomDialog.desc_intro")}</p>
|
|
|
|
|
<p>{`🔒 ${t("roomDialog.desc_privacy")}`}</p>
|
|
|
|
|
<div className="RoomDialog-sessionStartButtonContainer">
|
|
|
|
|
<ToolButton
|
|
|
|
|
className="RoomDialog-startSession"
|
|
|
|
|
type="button"
|
|
|
|
|
icon={start}
|
|
|
|
|
title={t("roomDialog.button_startSession")}
|
|
|
|
|
aria-label={t("roomDialog.button_startSession")}
|
|
|
|
|
showAriaLabel={true}
|
|
|
|
|
onClick={onRoomCreate}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{activeRoomLink && (
|
|
|
|
|
<>
|
|
|
|
|
<p>{t("roomDialog.desc_inProgressIntro")}</p>
|
|
|
|
|
<p>{t("roomDialog.desc_shareLink")}</p>
|
|
|
|
|
<div className="RoomDialog-linkContainer">
|
|
|
|
|
<ToolButton
|
|
|
|
|
type="button"
|
|
|
|
|
icon={clipboard}
|
|
|
|
|
title={t("labels.copy")}
|
|
|
|
|
aria-label={t("labels.copy")}
|
|
|
|
|
onClick={copyRoomLink}
|
|
|
|
|
/>
|
|
|
|
|
<input
|
|
|
|
|
value={activeRoomLink}
|
|
|
|
|
readOnly={true}
|
|
|
|
|
className="RoomDialog-link"
|
|
|
|
|
ref={roomLinkInput}
|
|
|
|
|
onPointerDown={selectInput}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2020-04-07 14:02:42 +01:00
|
|
|
|
<div className="RoomDialog-usernameContainer">
|
|
|
|
|
<label className="RoomDialog-usernameLabel" htmlFor="username">
|
2020-04-10 18:12:51 +03:00
|
|
|
|
{t("labels.name")}
|
2020-04-07 14:02:42 +01:00
|
|
|
|
</label>
|
|
|
|
|
<input
|
|
|
|
|
id="username"
|
|
|
|
|
value={username || ""}
|
2020-04-10 18:09:29 -04:00
|
|
|
|
className="RoomDialog-username TextInput"
|
2020-04-07 14:02:42 +01:00
|
|
|
|
onChange={(event) => onUsernameChange(event.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2020-03-13 15:32:47 -04:00
|
|
|
|
<p>{`🔒 ${t("roomDialog.desc_privacy")}`}</p>
|
|
|
|
|
<p>
|
|
|
|
|
<span role="img" aria-hidden="true">
|
|
|
|
|
⚠️
|
|
|
|
|
</span>{" "}
|
|
|
|
|
{t("roomDialog.desc_persistenceWarning")}
|
|
|
|
|
</p>
|
|
|
|
|
<p>{t("roomDialog.desc_exitSession")}</p>
|
|
|
|
|
<div className="RoomDialog-sessionStartButtonContainer">
|
|
|
|
|
<ToolButton
|
|
|
|
|
className="RoomDialog-stopSession"
|
|
|
|
|
type="button"
|
|
|
|
|
icon={stop}
|
|
|
|
|
title={t("roomDialog.button_stopSession")}
|
|
|
|
|
aria-label={t("roomDialog.button_stopSession")}
|
|
|
|
|
showAriaLabel={true}
|
|
|
|
|
onClick={onRoomDestroy}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2020-03-11 19:42:18 +01:00
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function RoomDialog({
|
|
|
|
|
isCollaborating,
|
2020-03-11 22:48:27 +01:00
|
|
|
|
collaboratorCount,
|
2020-04-07 14:02:42 +01:00
|
|
|
|
username,
|
|
|
|
|
onUsernameChange,
|
2020-03-11 19:42:18 +01:00
|
|
|
|
onRoomCreate,
|
|
|
|
|
onRoomDestroy,
|
|
|
|
|
}: {
|
2020-03-11 22:48:27 +01:00
|
|
|
|
isCollaborating: AppState["isCollaborating"];
|
2020-03-12 12:19:56 +01:00
|
|
|
|
collaboratorCount: number;
|
2020-04-07 14:02:42 +01:00
|
|
|
|
username: string;
|
|
|
|
|
onUsernameChange: (username: string) => void;
|
2020-03-11 19:42:18 +01:00
|
|
|
|
onRoomCreate: () => void;
|
|
|
|
|
onRoomDestroy: () => void;
|
|
|
|
|
}) {
|
|
|
|
|
const [modalIsShown, setModalIsShown] = useState(false);
|
|
|
|
|
const [activeRoomLink, setActiveRoomLink] = useState("");
|
|
|
|
|
|
|
|
|
|
const triggerButton = useRef<HTMLButtonElement>(null);
|
|
|
|
|
|
|
|
|
|
const handleClose = React.useCallback(() => {
|
|
|
|
|
setModalIsShown(false);
|
|
|
|
|
triggerButton.current?.focus();
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setActiveRoomLink(isCollaborating ? window.location.href : "");
|
|
|
|
|
}, [isCollaborating]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<ToolButton
|
|
|
|
|
className={`RoomDialog-modalButton ${
|
|
|
|
|
isCollaborating ? "is-collaborating" : ""
|
|
|
|
|
}`}
|
|
|
|
|
onClick={() => setModalIsShown(true)}
|
|
|
|
|
icon={users}
|
|
|
|
|
type="button"
|
|
|
|
|
title={t("buttons.roomDialog")}
|
|
|
|
|
aria-label={t("buttons.roomDialog")}
|
|
|
|
|
showAriaLabel={useIsMobile()}
|
|
|
|
|
ref={triggerButton}
|
2020-03-11 22:48:27 +01:00
|
|
|
|
>
|
|
|
|
|
{collaboratorCount > 0 && (
|
|
|
|
|
<div className="RoomDialog-modalButton-collaborators">
|
|
|
|
|
{collaboratorCount}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</ToolButton>
|
2020-03-11 19:42:18 +01:00
|
|
|
|
{modalIsShown && (
|
2020-03-13 15:32:47 -04:00
|
|
|
|
<Dialog
|
2020-03-11 19:42:18 +01:00
|
|
|
|
maxWidth={800}
|
|
|
|
|
onCloseRequest={handleClose}
|
2020-03-13 15:32:47 -04:00
|
|
|
|
title={t("labels.createRoom")}
|
2020-03-11 19:42:18 +01:00
|
|
|
|
>
|
|
|
|
|
<RoomModal
|
|
|
|
|
activeRoomLink={activeRoomLink}
|
2020-04-07 14:02:42 +01:00
|
|
|
|
username={username}
|
|
|
|
|
onUsernameChange={onUsernameChange}
|
2020-03-11 19:42:18 +01:00
|
|
|
|
onRoomCreate={onRoomCreate}
|
|
|
|
|
onRoomDestroy={onRoomDestroy}
|
|
|
|
|
/>
|
2020-03-13 15:32:47 -04:00
|
|
|
|
</Dialog>
|
2020-03-11 19:42:18 +01:00
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|