2021-08-20 08:49:45 +08:00
|
|
|
import classNames from "classnames";
|
2022-07-30 15:50:16 +08:00
|
|
|
import React, { HTMLAttributes, ReactNode, useCallback, useRef } from "react";
|
2021-12-03 09:21:37 +08:00
|
|
|
import { Link } from "react-router-dom";
|
2022-07-30 15:50:16 +08:00
|
|
|
import { useButton } from "@react-aria/button";
|
|
|
|
import { AriaButtonProps } from "@react-types/button";
|
2022-08-13 04:46:53 +08:00
|
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
2022-10-10 21:19:10 +08:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-07-30 15:50:16 +08:00
|
|
|
|
2021-08-20 08:49:45 +08:00
|
|
|
import styles from "./Header.module.css";
|
2022-07-30 15:50:16 +08:00
|
|
|
import { useModalTriggerState } from "./Modal";
|
|
|
|
import { Button } from "./button";
|
2021-12-08 04:20:05 +08:00
|
|
|
import { ReactComponent as Logo } from "./icons/Logo.svg";
|
2021-11-30 08:19:48 +08:00
|
|
|
import { ReactComponent as VideoIcon } from "./icons/Video.svg";
|
2022-01-06 03:52:23 +08:00
|
|
|
import { Subtitle } from "./typography/Typography";
|
2022-07-30 15:50:16 +08:00
|
|
|
import { Avatar, Size } from "./Avatar";
|
2022-06-10 19:06:06 +08:00
|
|
|
import { IncompatibleVersionModal } from "./IncompatibleVersionModal";
|
2022-07-30 15:50:16 +08:00
|
|
|
import { ReactComponent as ArrowLeftIcon } from "./icons/ArrowLeft.svg";
|
|
|
|
|
|
|
|
interface HeaderProps extends HTMLAttributes<HTMLElement> {
|
|
|
|
children: ReactNode;
|
|
|
|
className?: string;
|
|
|
|
}
|
2021-08-20 08:49:45 +08:00
|
|
|
|
2022-07-30 15:50:16 +08:00
|
|
|
export function Header({ children, className, ...rest }: HeaderProps) {
|
2021-08-20 08:49:45 +08:00
|
|
|
return (
|
2021-11-30 08:19:48 +08:00
|
|
|
<header className={classNames(styles.header, className)} {...rest}>
|
2021-08-20 08:49:45 +08:00
|
|
|
{children}
|
2021-11-30 08:19:48 +08:00
|
|
|
</header>
|
2021-08-20 08:49:45 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-30 15:50:16 +08:00
|
|
|
interface LeftNavProps extends HTMLAttributes<HTMLElement> {
|
|
|
|
children: ReactNode;
|
|
|
|
className?: string;
|
|
|
|
hideMobile?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function LeftNav({
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
hideMobile,
|
|
|
|
...rest
|
|
|
|
}: LeftNavProps) {
|
2021-08-20 08:49:45 +08:00
|
|
|
return (
|
2021-11-30 08:19:48 +08:00
|
|
|
<div
|
2021-12-24 06:40:23 +08:00
|
|
|
className={classNames(
|
|
|
|
styles.nav,
|
|
|
|
styles.leftNav,
|
|
|
|
{ [styles.hideMobile]: hideMobile },
|
|
|
|
className
|
|
|
|
)}
|
2021-11-30 08:19:48 +08:00
|
|
|
{...rest}
|
|
|
|
>
|
2021-08-20 08:49:45 +08:00
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2021-08-21 07:23:12 +08:00
|
|
|
|
2022-08-01 04:09:33 +08:00
|
|
|
interface RightNavProps extends HTMLAttributes<HTMLElement> {
|
2022-07-30 15:50:16 +08:00
|
|
|
children?: ReactNode;
|
|
|
|
className?: string;
|
2022-08-19 06:48:24 +08:00
|
|
|
hideMobile?: boolean;
|
2022-07-30 15:50:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function RightNav({
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
hideMobile,
|
|
|
|
...rest
|
|
|
|
}: RightNavProps) {
|
2021-08-21 07:23:12 +08:00
|
|
|
return (
|
2021-11-30 08:19:48 +08:00
|
|
|
<div
|
2022-01-05 08:00:13 +08:00
|
|
|
className={classNames(
|
|
|
|
styles.nav,
|
|
|
|
styles.rightNav,
|
|
|
|
{ [styles.hideMobile]: hideMobile },
|
|
|
|
className
|
|
|
|
)}
|
2021-11-30 08:19:48 +08:00
|
|
|
{...rest}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</div>
|
2021-08-21 07:23:12 +08:00
|
|
|
);
|
|
|
|
}
|
2021-12-03 09:21:37 +08:00
|
|
|
|
2022-07-30 15:50:16 +08:00
|
|
|
interface HeaderLogoProps {
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function HeaderLogo({ className }: HeaderLogoProps) {
|
2021-12-03 09:21:37 +08:00
|
|
|
return (
|
2022-11-05 02:31:21 +08:00
|
|
|
<Link
|
|
|
|
className={classNames(styles.headerLogo, className)}
|
|
|
|
to="/"
|
|
|
|
aria-label="Element Call Home"
|
|
|
|
>
|
2021-12-08 04:20:05 +08:00
|
|
|
<Logo />
|
2021-12-03 09:21:37 +08:00
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-30 15:50:16 +08:00
|
|
|
interface RoomHeaderInfo {
|
|
|
|
roomName: string;
|
|
|
|
avatarUrl: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function RoomHeaderInfo({ roomName, avatarUrl }: RoomHeaderInfo) {
|
2021-12-03 09:21:37 +08:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className={styles.roomAvatar}>
|
2022-01-22 08:41:00 +08:00
|
|
|
<Avatar
|
2022-07-30 15:50:16 +08:00
|
|
|
size={Size.MD}
|
2022-05-19 07:00:59 +08:00
|
|
|
src={avatarUrl}
|
2022-01-22 08:41:00 +08:00
|
|
|
bgKey={roomName}
|
|
|
|
fallback={roomName.slice(0, 1).toUpperCase()}
|
|
|
|
/>
|
2021-12-03 09:21:37 +08:00
|
|
|
<VideoIcon width={16} height={16} />
|
|
|
|
</div>
|
2022-01-06 03:52:23 +08:00
|
|
|
<Subtitle fontWeight="semiBold">{roomName}</Subtitle>
|
2021-12-03 09:21:37 +08:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-30 15:50:16 +08:00
|
|
|
interface RoomSetupHeaderInfoProps extends AriaButtonProps<"button"> {
|
|
|
|
roomName: string;
|
|
|
|
avatarUrl: string;
|
|
|
|
isEmbedded: boolean;
|
|
|
|
}
|
|
|
|
|
2022-06-28 22:08:14 +08:00
|
|
|
export function RoomSetupHeaderInfo({
|
|
|
|
roomName,
|
|
|
|
avatarUrl,
|
|
|
|
isEmbedded,
|
|
|
|
...rest
|
2022-07-30 15:50:16 +08:00
|
|
|
}: RoomSetupHeaderInfoProps) {
|
2021-12-08 03:59:57 +08:00
|
|
|
const ref = useRef();
|
|
|
|
const { buttonProps } = useButton(rest, ref);
|
2022-06-28 22:08:14 +08:00
|
|
|
|
|
|
|
if (isEmbedded) {
|
|
|
|
return (
|
2022-07-01 20:10:08 +08:00
|
|
|
<div ref={ref}>
|
2022-06-28 22:08:14 +08:00
|
|
|
<RoomHeaderInfo roomName={roomName} avatarUrl={avatarUrl} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-03 09:21:37 +08:00
|
|
|
return (
|
2021-12-08 03:59:57 +08:00
|
|
|
<button className={styles.backButton} ref={ref} {...buttonProps}>
|
2021-12-03 09:21:37 +08:00
|
|
|
<ArrowLeftIcon width={16} height={16} />
|
2022-05-19 07:00:59 +08:00
|
|
|
<RoomHeaderInfo roomName={roomName} avatarUrl={avatarUrl} />
|
2021-12-03 09:21:37 +08:00
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
2022-06-10 04:56:58 +08:00
|
|
|
|
2022-07-30 15:50:16 +08:00
|
|
|
interface VersionMismatchWarningProps {
|
|
|
|
users: Set<string>;
|
|
|
|
room: Room;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function VersionMismatchWarning({
|
|
|
|
users,
|
|
|
|
room,
|
|
|
|
}: VersionMismatchWarningProps) {
|
2022-10-10 21:19:10 +08:00
|
|
|
const { t } = useTranslation();
|
2022-06-10 04:56:58 +08:00
|
|
|
const { modalState, modalProps } = useModalTriggerState();
|
|
|
|
|
|
|
|
const onDetailsClick = useCallback(() => {
|
|
|
|
modalState.open();
|
|
|
|
}, [modalState]);
|
|
|
|
|
|
|
|
if (users.size === 0) return null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span className={styles.versionMismatchWarning}>
|
2022-10-10 21:19:10 +08:00
|
|
|
{t("Incompatible versions!")}
|
2022-06-10 04:56:58 +08:00
|
|
|
<Button variant="link" onClick={onDetailsClick}>
|
2022-10-10 21:19:10 +08:00
|
|
|
{t("Details")}
|
2022-06-10 04:56:58 +08:00
|
|
|
</Button>
|
|
|
|
{modalState.isOpen && (
|
2022-06-10 19:06:06 +08:00
|
|
|
<IncompatibleVersionModal userIds={users} room={room} {...modalProps} />
|
2022-06-10 04:56:58 +08:00
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|