Files
element-call/src/DisconnectedBanner.tsx
T

45 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-06-09 19:18:30 +02:00
/*
Copyright 2023, 2024 New Vector Ltd.
2023-06-09 19:18:30 +02:00
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
2023-06-09 19:18:30 +02:00
*/
import classNames from "classnames";
import { type FC, type HTMLAttributes, type ReactNode } from "react";
2023-06-12 10:14:11 +02:00
import { useTranslation } from "react-i18next";
2023-06-09 19:18:30 +02:00
import styles from "./DisconnectedBanner.module.css";
import { type ValidClientState, useClientState } from "./ClientContext";
2023-06-09 19:18:30 +02:00
2023-09-22 18:05:13 -04:00
interface Props extends HTMLAttributes<HTMLElement> {
2023-06-09 19:18:30 +02:00
children?: ReactNode;
className?: string;
}
2023-09-22 18:05:13 -04:00
export const DisconnectedBanner: FC<Props> = ({
2023-06-09 19:18:30 +02:00
children,
className,
...rest
2023-09-22 18:05:13 -04:00
}) => {
2023-06-12 10:14:11 +02:00
const { t } = useTranslation();
const clientState = useClientState();
let shouldShowBanner = false;
if (clientState?.state === "valid") {
const validClientState = clientState as ValidClientState;
shouldShowBanner = validClientState.disconnected;
}
2023-06-12 10:14:11 +02:00
2023-06-09 19:18:30 +02:00
return (
<>
{shouldShowBanner && (
2023-06-12 10:14:11 +02:00
<div className={classNames(styles.banner, className)} {...rest}>
{children}
2023-11-20 13:00:43 +00:00
{t("disconnected_banner")}
2023-06-12 10:14:11 +02:00
</div>
2023-06-09 19:18:30 +02:00
)}
</>
);
2023-09-22 18:05:13 -04:00
};