2023-01-03 16:55:26 +00:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2021-08-20 00:49:45 +00:00
|
|
|
import classNames from "classnames";
|
2023-06-30 22:21:18 +00:00
|
|
|
import { HTMLAttributes, ReactNode, useCallback } from "react";
|
2021-12-03 01:21:37 +00:00
|
|
|
import { Link } from "react-router-dom";
|
2022-08-12 20:46:53 +00:00
|
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
2022-10-10 13:19:10 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-07-30 07:50:16 +00:00
|
|
|
|
2021-08-20 00:49:45 +00:00
|
|
|
import styles from "./Header.module.css";
|
2022-07-30 07:50:16 +00:00
|
|
|
import { useModalTriggerState } from "./Modal";
|
|
|
|
import { Button } from "./button";
|
2021-12-07 20:20:05 +00:00
|
|
|
import { ReactComponent as Logo } from "./icons/Logo.svg";
|
2022-01-05 19:52:23 +00:00
|
|
|
import { Subtitle } from "./typography/Typography";
|
2022-06-10 11:06:06 +00:00
|
|
|
import { IncompatibleVersionModal } from "./IncompatibleVersionModal";
|
2022-07-30 07:50:16 +00:00
|
|
|
|
|
|
|
interface HeaderProps extends HTMLAttributes<HTMLElement> {
|
|
|
|
children: ReactNode;
|
|
|
|
className?: string;
|
|
|
|
}
|
2021-08-20 00:49:45 +00:00
|
|
|
|
2022-07-30 07:50:16 +00:00
|
|
|
export function Header({ children, className, ...rest }: HeaderProps) {
|
2021-08-20 00:49:45 +00:00
|
|
|
return (
|
2021-11-30 00:19:48 +00:00
|
|
|
<header className={classNames(styles.header, className)} {...rest}>
|
2021-08-20 00:49:45 +00:00
|
|
|
{children}
|
2021-11-30 00:19:48 +00:00
|
|
|
</header>
|
2021-08-20 00:49:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-30 07:50:16 +00:00
|
|
|
interface LeftNavProps extends HTMLAttributes<HTMLElement> {
|
|
|
|
children: ReactNode;
|
|
|
|
className?: string;
|
|
|
|
hideMobile?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function LeftNav({
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
hideMobile,
|
|
|
|
...rest
|
|
|
|
}: LeftNavProps) {
|
2021-08-20 00:49:45 +00:00
|
|
|
return (
|
2021-11-30 00:19:48 +00:00
|
|
|
<div
|
2021-12-23 22:40:23 +00:00
|
|
|
className={classNames(
|
|
|
|
styles.nav,
|
|
|
|
styles.leftNav,
|
|
|
|
{ [styles.hideMobile]: hideMobile },
|
|
|
|
className
|
|
|
|
)}
|
2021-11-30 00:19:48 +00:00
|
|
|
{...rest}
|
|
|
|
>
|
2021-08-20 00:49:45 +00:00
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2021-08-20 23:23:12 +00:00
|
|
|
|
2022-07-31 20:09:33 +00:00
|
|
|
interface RightNavProps extends HTMLAttributes<HTMLElement> {
|
2022-07-30 07:50:16 +00:00
|
|
|
children?: ReactNode;
|
|
|
|
className?: string;
|
2022-08-18 22:48:24 +00:00
|
|
|
hideMobile?: boolean;
|
2022-07-30 07:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function RightNav({
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
hideMobile,
|
|
|
|
...rest
|
|
|
|
}: RightNavProps) {
|
2021-08-20 23:23:12 +00:00
|
|
|
return (
|
2021-11-30 00:19:48 +00:00
|
|
|
<div
|
2022-01-05 00:00:13 +00:00
|
|
|
className={classNames(
|
|
|
|
styles.nav,
|
|
|
|
styles.rightNav,
|
|
|
|
{ [styles.hideMobile]: hideMobile },
|
|
|
|
className
|
|
|
|
)}
|
2021-11-30 00:19:48 +00:00
|
|
|
{...rest}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</div>
|
2021-08-20 23:23:12 +00:00
|
|
|
);
|
|
|
|
}
|
2021-12-03 01:21:37 +00:00
|
|
|
|
2022-07-30 07:50:16 +00:00
|
|
|
interface HeaderLogoProps {
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function HeaderLogo({ className }: HeaderLogoProps) {
|
2022-11-07 12:33:06 +00:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
2021-12-03 01:21:37 +00:00
|
|
|
return (
|
2022-11-04 18:31:21 +00:00
|
|
|
<Link
|
|
|
|
className={classNames(styles.headerLogo, className)}
|
|
|
|
to="/"
|
2022-11-07 12:33:06 +00:00
|
|
|
aria-label={t("Element Call Home")}
|
2022-11-04 18:31:21 +00:00
|
|
|
>
|
2021-12-07 20:20:05 +00:00
|
|
|
<Logo />
|
2021-12-03 01:21:37 +00:00
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-30 07:50:16 +00:00
|
|
|
interface RoomHeaderInfo {
|
|
|
|
roomName: string;
|
|
|
|
}
|
|
|
|
|
2023-06-29 06:03:30 +00:00
|
|
|
export function RoomHeaderInfo({ roomName }: RoomHeaderInfo) {
|
2021-12-03 01:21:37 +00:00
|
|
|
return (
|
|
|
|
<>
|
2023-05-11 14:16:17 +00:00
|
|
|
<Subtitle data-testid="roomHeader_roomName" fontWeight="semiBold">
|
|
|
|
{roomName}
|
|
|
|
</Subtitle>
|
2021-12-03 01:21:37 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-30 07:50:16 +00:00
|
|
|
interface VersionMismatchWarningProps {
|
|
|
|
users: Set<string>;
|
|
|
|
room: Room;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function VersionMismatchWarning({
|
|
|
|
users,
|
|
|
|
room,
|
|
|
|
}: VersionMismatchWarningProps) {
|
2022-10-10 13:19:10 +00:00
|
|
|
const { t } = useTranslation();
|
2022-06-09 20:56:58 +00: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 13:19:10 +00:00
|
|
|
{t("Incompatible versions!")}
|
2022-06-09 20:56:58 +00:00
|
|
|
<Button variant="link" onClick={onDetailsClick}>
|
2022-10-10 13:19:10 +00:00
|
|
|
{t("Details")}
|
2022-06-09 20:56:58 +00:00
|
|
|
</Button>
|
|
|
|
{modalState.isOpen && (
|
2022-06-10 11:06:06 +00:00
|
|
|
<IncompatibleVersionModal userIds={users} room={room} {...modalProps} />
|
2022-06-09 20:56:58 +00:00
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|