Files
ThreadNet-Web/src/components/views/user-onboarding/UserOnboardingPage.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
3.0 KiB
TypeScript
Raw Normal View History

2022-07-29 13:43:29 +02:00
/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
2022-07-29 13:43:29 +02:00
Copyright 2020-2022 The Matrix.org Foundation C.I.C.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
2024-09-09 14:57:16 +01:00
Please see LICENSE files in the repository root for full details.
2022-07-29 13:43:29 +02:00
*/
import { useEffect, useState } from "react";
import * as React from "react";
import { useInitialSyncComplete } from "../../../hooks/useIsInitialSyncComplete";
import { useSettingValue } from "../../../hooks/useSettings";
import { useUserOnboardingContext } from "../../../hooks/useUserOnboardingContext";
2022-07-29 13:43:29 +02:00
import { useUserOnboardingTasks } from "../../../hooks/useUserOnboardingTasks";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import SdkConfig from "../../../SdkConfig";
import { UseCase } from "../../../settings/enums/UseCase";
import { getHomePageUrl } from "../../../utils/pages";
import AutoHideScrollbar from "../../structures/AutoHideScrollbar";
import EmbeddedPage from "../../structures/EmbeddedPage";
import HomePage from "../../structures/HomePage";
import { UserOnboardingHeader } from "./UserOnboardingHeader";
import { UserOnboardingList } from "./UserOnboardingList";
import { useMatrixClientContext } from "../../../contexts/MatrixClientContext";
2022-07-29 13:43:29 +02:00
interface Props {
justRegistered?: boolean;
}
// We decided to only show the new user onboarding page to new users
// For now, that means we set the cutoff at 2022-07-01 00:00 UTC
const USER_ONBOARDING_CUTOFF_DATE = new Date(1_656_633_600);
export function showUserOnboardingPage(useCase: UseCase | null): boolean {
2022-07-29 13:43:29 +02:00
return useCase !== null || MatrixClientPeg.userRegisteredAfter(USER_ONBOARDING_CUTOFF_DATE);
}
const ANIMATION_DURATION = 2800;
export function UserOnboardingPage({ justRegistered = false }: Props): JSX.Element {
const cli = useMatrixClientContext();
2022-07-29 13:43:29 +02:00
const config = SdkConfig.get();
const pageUrl = getHomePageUrl(config, cli);
2022-07-29 13:43:29 +02:00
2024-12-23 20:25:15 +00:00
const useCase = useSettingValue("FTUE.useCaseSelection");
const context = useUserOnboardingContext();
2023-01-02 15:34:34 +01:00
const tasks = useUserOnboardingTasks(context);
2022-07-29 13:43:29 +02:00
const initialSyncComplete = useInitialSyncComplete();
const [showList, setShowList] = useState<boolean>(false);
useEffect(() => {
if (initialSyncComplete) {
const handler = window.setTimeout(() => {
2022-07-29 13:43:29 +02:00
setShowList(true);
}, ANIMATION_DURATION);
return () => {
clearTimeout(handler);
};
} else {
setShowList(false);
}
}, [initialSyncComplete, setShowList]);
// Only show new onboarding list to users who registered after a given date or have chosen a use case
if (!showUserOnboardingPage(useCase)) {
return <HomePage justRegistered={justRegistered} />;
}
if (pageUrl) {
return <EmbeddedPage className="mx_HomePage" url={pageUrl} scrollbar={true} />;
}
return (
<AutoHideScrollbar className="mx_UserOnboardingPage">
<UserOnboardingHeader useCase={useCase} />
2023-01-02 15:34:34 +01:00
{showList && <UserOnboardingList tasks={tasks} />}
2022-07-29 13:43:29 +02:00
</AutoHideScrollbar>
);
}