2021-08-19 17:49:45 -07:00
|
|
|
/*
|
2024-09-06 10:22:13 +02:00
|
|
|
Copyright 2021-2024 New Vector Ltd.
|
2021-08-19 17:49:45 -07:00
|
|
|
|
2025-02-18 17:59:58 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-06 10:22:13 +02:00
|
|
|
Please see LICENSE in the repository root for full details.
|
2021-08-19 17:49:45 -07:00
|
|
|
*/
|
|
|
|
|
|
2022-10-10 09:19:10 -04:00
|
|
|
import { useTranslation } from "react-i18next";
|
2024-12-11 09:27:55 +00:00
|
|
|
import { type FC } from "react";
|
2022-07-28 00:17:09 +02:00
|
|
|
|
2023-06-30 16:43:28 +01:00
|
|
|
import { useClientState } from "../ClientContext";
|
2025-01-17 04:35:39 -05:00
|
|
|
import { ErrorPage, LoadingPage } from "../FullScreenView";
|
2022-01-04 17:09:27 -08:00
|
|
|
import { UnauthenticatedView } from "./UnauthenticatedView";
|
|
|
|
|
import { RegisteredView } from "./RegisteredView";
|
2022-02-02 15:02:40 -08:00
|
|
|
import { usePageTitle } from "../usePageTitle";
|
2025-03-07 10:12:23 +01:00
|
|
|
import { widget } from "../widget.ts";
|
2021-12-09 12:58:30 -08:00
|
|
|
|
2023-09-22 18:05:13 -04:00
|
|
|
export const HomePage: FC = () => {
|
2022-10-10 09:19:10 -04:00
|
|
|
const { t } = useTranslation();
|
2023-11-20 11:05:18 +00:00
|
|
|
usePageTitle(t("common.home"));
|
2022-02-02 15:02:40 -08:00
|
|
|
|
2023-06-30 16:43:28 +01:00
|
|
|
const clientState = useClientState();
|
2021-12-17 15:01:59 -08:00
|
|
|
|
2023-06-30 16:43:28 +01:00
|
|
|
if (!clientState) {
|
2025-01-17 04:35:39 -05:00
|
|
|
return <LoadingPage />;
|
2023-06-30 16:43:28 +01:00
|
|
|
} else if (clientState.state === "error") {
|
2025-03-07 10:12:23 +01:00
|
|
|
return <ErrorPage widget={widget} error={clientState.error} />;
|
2021-12-10 10:54:18 -08:00
|
|
|
} else {
|
2023-06-30 16:43:28 +01:00
|
|
|
return clientState.authenticated ? (
|
2023-09-18 11:06:06 -04:00
|
|
|
<RegisteredView client={clientState.authenticated.client} />
|
2022-01-04 16:00:13 -08:00
|
|
|
) : (
|
|
|
|
|
<UnauthenticatedView />
|
2021-12-10 10:54:18 -08:00
|
|
|
);
|
|
|
|
|
}
|
2023-09-22 18:05:13 -04:00
|
|
|
};
|