```
move () {
FROM=$1 TO=$2 find public/locales -type f -exec sh -c 'jq ".$TO = .\"$FROM\" | del(.\"$FROM\") | del(..|nulls) | select(length > 0)" {} | sponge {}' \;
}
move "Avatar" "common.avatar"
move "Camera" "common.camera"
move "Close" "action.close"
move "Copied!" "common.copied"
move "Copy" "action.copy"
move "Copy link" "action.copy_link"
move "Encrypted" "common.encrypted"
move "Go" "action.go"
move "Home" "common.home"
move "Invite" "action.invite"
move "Loading…" "common.loading"
move "Microphone" "common.microphone"
move "No" "action.no"
move "Not encrypted" "common.unencrypted"
move "Password" "common.password"
move "Profile" "common.profile"
move "Username" "common.username"
move "Video" "common.video"
move "Register" "action.register"
move "Remove" "action.remove"
move "Settings" "common.settings"
move "Sign in" "action.sign_in"
move "Sign out" "action.sign_out"
move "Submit" "action.submit"
move "User menu" "a11y.user_menu"
move "Audio" "common.audio"
move "Display name" "common.display_name"
```
177 lines
5.5 KiB
TypeScript
177 lines
5.5 KiB
TypeScript
/*
|
|
Copyright 2022 New Vector Ltd
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
import { useState, useCallback, FormEvent, FormEventHandler, FC } from "react";
|
|
import { useHistory } from "react-router-dom";
|
|
import { MatrixClient } from "matrix-js-sdk/src/client";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Heading } from "@vector-im/compound-web";
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
|
|
|
import {
|
|
createRoom,
|
|
getRelativeRoomUrl,
|
|
roomAliasLocalpartFromRoomName,
|
|
sanitiseRoomNameInput,
|
|
} from "../matrix-utils";
|
|
import { useGroupCallRooms } from "./useGroupCallRooms";
|
|
import { Header, HeaderLogo, LeftNav, RightNav } from "../Header";
|
|
import commonStyles from "./common.module.css";
|
|
import styles from "./RegisteredView.module.css";
|
|
import { FieldRow, InputField, ErrorMessage } from "../input/Input";
|
|
import { Button } from "../button";
|
|
import { CallList } from "./CallList";
|
|
import { UserMenuContainer } from "../UserMenuContainer";
|
|
import { JoinExistingCallModal } from "./JoinExistingCallModal";
|
|
import { Caption } from "../typography/Typography";
|
|
import { Form } from "../form/Form";
|
|
import { useOptInAnalytics } from "../settings/useSetting";
|
|
import { AnalyticsNotice } from "../analytics/AnalyticsNotice";
|
|
import { E2eeType } from "../e2ee/e2eeType";
|
|
|
|
interface Props {
|
|
client: MatrixClient;
|
|
}
|
|
|
|
export const RegisteredView: FC<Props> = ({ client }) => {
|
|
const [loading, setLoading] = useState(false);
|
|
const [error, setError] = useState<Error>();
|
|
const [optInAnalytics] = useOptInAnalytics();
|
|
const history = useHistory();
|
|
const { t } = useTranslation();
|
|
const [joinExistingCallModalOpen, setJoinExistingCallModalOpen] =
|
|
useState(false);
|
|
const onDismissJoinExistingCallModal = useCallback(
|
|
() => setJoinExistingCallModalOpen(false),
|
|
[setJoinExistingCallModalOpen],
|
|
);
|
|
|
|
const onSubmit: FormEventHandler<HTMLFormElement> = useCallback(
|
|
(e: FormEvent) => {
|
|
e.preventDefault();
|
|
const data = new FormData(e.target as HTMLFormElement);
|
|
const roomNameData = data.get("callName");
|
|
const roomName =
|
|
typeof roomNameData === "string"
|
|
? sanitiseRoomNameInput(roomNameData)
|
|
: "";
|
|
|
|
async function submit(): Promise<void> {
|
|
setError(undefined);
|
|
setLoading(true);
|
|
|
|
const createRoomResult = await createRoom(
|
|
client,
|
|
roomName,
|
|
E2eeType.SHARED_KEY,
|
|
);
|
|
|
|
history.push(
|
|
getRelativeRoomUrl(
|
|
createRoomResult.roomId,
|
|
roomName,
|
|
createRoomResult.password,
|
|
),
|
|
);
|
|
}
|
|
|
|
submit().catch((error) => {
|
|
if (error.errcode === "M_ROOM_IN_USE") {
|
|
setExistingAlias(roomAliasLocalpartFromRoomName(roomName));
|
|
setLoading(false);
|
|
setError(undefined);
|
|
setJoinExistingCallModalOpen(true);
|
|
} else {
|
|
logger.error(error);
|
|
setLoading(false);
|
|
setError(error);
|
|
}
|
|
});
|
|
},
|
|
[client, history, setJoinExistingCallModalOpen],
|
|
);
|
|
|
|
const recentRooms = useGroupCallRooms(client);
|
|
|
|
const [existingAlias, setExistingAlias] = useState<string>();
|
|
const onJoinExistingRoom = useCallback(() => {
|
|
history.push(`/${existingAlias}`);
|
|
}, [history, existingAlias]);
|
|
|
|
return (
|
|
<>
|
|
<div className={commonStyles.container}>
|
|
<Header>
|
|
<LeftNav>
|
|
<HeaderLogo />
|
|
</LeftNav>
|
|
<RightNav>
|
|
<UserMenuContainer />
|
|
</RightNav>
|
|
</Header>
|
|
<main className={commonStyles.main}>
|
|
<HeaderLogo className={commonStyles.logo} />
|
|
<Heading size="lg" weight="semibold">
|
|
{t("Start new call")}
|
|
</Heading>
|
|
<Form className={styles.form} onSubmit={onSubmit}>
|
|
<FieldRow className={styles.fieldRow}>
|
|
<InputField
|
|
id="callName"
|
|
name="callName"
|
|
label={t("Name of call")}
|
|
placeholder={t("Name of call")}
|
|
type="text"
|
|
required
|
|
autoComplete="off"
|
|
data-testid="home_callName"
|
|
/>
|
|
|
|
<Button
|
|
type="submit"
|
|
size="lg"
|
|
className={styles.button}
|
|
disabled={loading}
|
|
data-testid="home_go"
|
|
>
|
|
{loading ? t("common.loading") : t("action.go")}
|
|
</Button>
|
|
</FieldRow>
|
|
{optInAnalytics === null && (
|
|
<Caption className={styles.notice}>
|
|
<AnalyticsNotice />
|
|
</Caption>
|
|
)}
|
|
{error && (
|
|
<FieldRow className={styles.fieldRow}>
|
|
<ErrorMessage error={error} />
|
|
</FieldRow>
|
|
)}
|
|
</Form>
|
|
{recentRooms.length > 0 && (
|
|
<CallList rooms={recentRooms} client={client} />
|
|
)}
|
|
</main>
|
|
</div>
|
|
<JoinExistingCallModal
|
|
onJoin={onJoinExistingRoom}
|
|
open={joinExistingCallModalOpen}
|
|
onDismiss={onDismissJoinExistingCallModal}
|
|
/>
|
|
</>
|
|
);
|
|
};
|