2020-12-05 20:00:53 +05:30
|
|
|
import React, { useRef } from "react";
|
|
|
|
import { copyTextToSystemClipboard } from "../../clipboard";
|
2021-01-05 20:06:14 +02:00
|
|
|
import { Dialog } from "../../components/Dialog";
|
2021-03-11 16:51:17 +05:30
|
|
|
import {
|
|
|
|
clipboard,
|
|
|
|
start,
|
|
|
|
stop,
|
|
|
|
share,
|
|
|
|
shareIOS,
|
2021-03-22 21:32:20 +05:30
|
|
|
shareWindows,
|
2021-03-11 16:51:17 +05:30
|
|
|
} from "../../components/icons";
|
2021-01-05 20:06:14 +02:00
|
|
|
import { ToolButton } from "../../components/ToolButton";
|
2020-12-05 20:00:53 +05:30
|
|
|
import "./RoomDialog.scss";
|
2021-03-11 16:51:17 +05:30
|
|
|
import Stack from "../../components/Stack";
|
2021-04-13 23:02:57 +05:30
|
|
|
import { AppState } from "../../types";
|
2022-07-05 16:03:40 +02:00
|
|
|
import { trackEvent } from "../../analytics";
|
|
|
|
import { getFrame } from "../../utils";
|
2022-11-01 17:29:58 +01:00
|
|
|
import DialogActionButton from "../../components/DialogActionButton";
|
2023-02-22 15:01:23 +01:00
|
|
|
import { useI18n } from "../../i18n";
|
2023-05-18 16:06:27 +02:00
|
|
|
import { KEYS } from "../../keys";
|
2020-12-05 20:00:53 +05:30
|
|
|
|
2021-03-22 21:32:20 +05:30
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
const RoomDialog = ({
|
|
|
|
handleClose,
|
|
|
|
activeRoomLink,
|
|
|
|
username,
|
|
|
|
onUsernameChange,
|
|
|
|
onRoomCreate,
|
|
|
|
onRoomDestroy,
|
|
|
|
setErrorMessage,
|
2021-04-13 23:02:57 +05:30
|
|
|
theme,
|
2020-12-05 20:00:53 +05:30
|
|
|
}: {
|
|
|
|
handleClose: () => void;
|
|
|
|
activeRoomLink: string;
|
|
|
|
username: string;
|
|
|
|
onUsernameChange: (username: string) => void;
|
|
|
|
onRoomCreate: () => void;
|
|
|
|
onRoomDestroy: () => void;
|
|
|
|
setErrorMessage: (message: string) => void;
|
2021-04-13 23:02:57 +05:30
|
|
|
theme: AppState["theme"];
|
2020-12-05 20:00:53 +05:30
|
|
|
}) => {
|
2023-02-22 15:01:23 +01:00
|
|
|
const { t } = useI18n();
|
2020-12-05 20:00:53 +05:30
|
|
|
const roomLinkInput = useRef<HTMLInputElement>(null);
|
|
|
|
|
|
|
|
const copyRoomLink = async () => {
|
|
|
|
try {
|
|
|
|
await copyTextToSystemClipboard(activeRoomLink);
|
2021-11-02 14:24:16 +02:00
|
|
|
} catch (error: any) {
|
2020-12-05 20:00:53 +05:30
|
|
|
setErrorMessage(error.message);
|
|
|
|
}
|
|
|
|
if (roomLinkInput.current) {
|
|
|
|
roomLinkInput.current.select();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-11 16:51:17 +05:30
|
|
|
const shareRoomLink = async () => {
|
|
|
|
try {
|
|
|
|
await navigator.share({
|
|
|
|
title: t("roomDialog.shareTitle"),
|
|
|
|
text: t("roomDialog.shareTitle"),
|
|
|
|
url: activeRoomLink,
|
|
|
|
});
|
2021-11-02 14:24:16 +02:00
|
|
|
} catch (error: any) {
|
2021-03-11 16:51:17 +05:30
|
|
|
// Just ignore.
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
const selectInput = (event: React.MouseEvent<HTMLInputElement>) => {
|
|
|
|
if (event.target !== document.activeElement) {
|
|
|
|
event.preventDefault();
|
|
|
|
(event.target as HTMLInputElement).select();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderRoomDialog = () => {
|
|
|
|
return (
|
|
|
|
<div className="RoomDialog-modal">
|
|
|
|
{!activeRoomLink && (
|
|
|
|
<>
|
|
|
|
<p>{t("roomDialog.desc_intro")}</p>
|
|
|
|
<p>{`🔒 ${t("roomDialog.desc_privacy")}`}</p>
|
|
|
|
<div className="RoomDialog-sessionStartButtonContainer">
|
2022-11-01 17:29:58 +01:00
|
|
|
<DialogActionButton
|
|
|
|
label={t("roomDialog.button_startSession")}
|
2022-07-05 16:03:40 +02:00
|
|
|
onClick={() => {
|
|
|
|
trackEvent("share", "room creation", `ui (${getFrame()})`);
|
|
|
|
onRoomCreate();
|
|
|
|
}}
|
2022-11-01 17:29:58 +01:00
|
|
|
>
|
|
|
|
{start}
|
|
|
|
</DialogActionButton>
|
2020-12-05 20:00:53 +05:30
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{activeRoomLink && (
|
|
|
|
<>
|
|
|
|
<p>{t("roomDialog.desc_inProgressIntro")}</p>
|
|
|
|
<p>{t("roomDialog.desc_shareLink")}</p>
|
|
|
|
<div className="RoomDialog-linkContainer">
|
2021-03-11 16:51:17 +05:30
|
|
|
<Stack.Row gap={2}>
|
|
|
|
{"share" in navigator ? (
|
|
|
|
<ToolButton
|
2022-11-01 17:29:58 +01:00
|
|
|
className="RoomDialog__button"
|
2021-03-11 16:51:17 +05:30
|
|
|
type="button"
|
2021-03-22 21:32:20 +05:30
|
|
|
icon={getShareIcon()}
|
2021-03-11 16:51:17 +05:30
|
|
|
title={t("labels.share")}
|
|
|
|
aria-label={t("labels.share")}
|
|
|
|
onClick={shareRoomLink}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<ToolButton
|
2022-11-01 17:29:58 +01:00
|
|
|
className="RoomDialog__button"
|
2021-03-11 16:51:17 +05:30
|
|
|
type="button"
|
|
|
|
icon={clipboard}
|
|
|
|
title={t("labels.copy")}
|
|
|
|
aria-label={t("labels.copy")}
|
|
|
|
onClick={copyRoomLink}
|
|
|
|
/>
|
|
|
|
</Stack.Row>
|
2020-12-05 20:00:53 +05:30
|
|
|
<input
|
2021-11-17 23:53:43 +05:30
|
|
|
type="text"
|
2020-12-05 20:00:53 +05:30
|
|
|
value={activeRoomLink}
|
|
|
|
readOnly={true}
|
|
|
|
className="RoomDialog-link"
|
|
|
|
ref={roomLinkInput}
|
|
|
|
onPointerDown={selectInput}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="RoomDialog-usernameContainer">
|
|
|
|
<label className="RoomDialog-usernameLabel" htmlFor="username">
|
|
|
|
{t("labels.yourName")}
|
|
|
|
</label>
|
|
|
|
<input
|
2021-11-17 23:53:43 +05:30
|
|
|
type="text"
|
2020-12-05 20:00:53 +05:30
|
|
|
id="username"
|
2023-02-09 15:51:49 +05:30
|
|
|
value={username.trim() || ""}
|
2020-12-05 20:00:53 +05:30
|
|
|
className="RoomDialog-username TextInput"
|
|
|
|
onChange={(event) => onUsernameChange(event.target.value)}
|
2023-05-18 16:06:27 +02:00
|
|
|
onKeyPress={(event) =>
|
|
|
|
event.key === KEYS.ENTER && handleClose()
|
|
|
|
}
|
2020-12-05 20:00:53 +05:30
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<p>
|
|
|
|
<span role="img" aria-hidden="true" className="RoomDialog-emoji">
|
|
|
|
{"🔒"}
|
2023-05-14 00:39:16 +03:30
|
|
|
</span>
|
2020-12-05 20:00:53 +05:30
|
|
|
{t("roomDialog.desc_privacy")}
|
|
|
|
</p>
|
|
|
|
<p>{t("roomDialog.desc_exitSession")}</p>
|
|
|
|
<div className="RoomDialog-sessionStartButtonContainer">
|
2022-11-01 17:29:58 +01:00
|
|
|
<DialogActionButton
|
|
|
|
actionType="danger"
|
|
|
|
label={t("roomDialog.button_stopSession")}
|
2022-07-05 16:03:40 +02:00
|
|
|
onClick={() => {
|
|
|
|
trackEvent("share", "room closed");
|
|
|
|
onRoomDestroy();
|
|
|
|
}}
|
2022-11-01 17:29:58 +01:00
|
|
|
>
|
|
|
|
{stop}
|
|
|
|
</DialogActionButton>
|
2020-12-05 20:00:53 +05:30
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
return (
|
2021-02-08 15:43:51 -05:00
|
|
|
<Dialog
|
|
|
|
small
|
|
|
|
onCloseRequest={handleClose}
|
|
|
|
title={t("labels.liveCollaboration")}
|
2021-04-13 23:02:57 +05:30
|
|
|
theme={theme}
|
2021-02-08 15:43:51 -05:00
|
|
|
>
|
2020-12-05 20:00:53 +05:30
|
|
|
{renderRoomDialog()}
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default RoomDialog;
|