2020-04-07 10:48:56 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2020-04-07 13:34:10 +01:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2020-04-07 10:48:56 +01:00
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
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.
|
2020-04-07 10:48:56 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import * as React from "react";
|
2021-06-29 13:11:58 +01:00
|
|
|
import { useContext, useState } from "react";
|
2020-04-07 10:48:56 +01:00
|
|
|
|
|
|
|
|
import AutoHideScrollbar from "./AutoHideScrollbar";
|
2021-06-29 13:11:58 +01:00
|
|
|
import { getHomePageUrl } from "../../utils/pages";
|
2024-10-18 15:57:39 +01:00
|
|
|
import { _t, _tDom } from "../../languageHandler";
|
2020-04-07 10:48:56 +01:00
|
|
|
import SdkConfig from "../../SdkConfig";
|
2020-05-13 20:41:41 -06:00
|
|
|
import dis from "../../dispatcher/dispatcher";
|
2021-06-29 13:11:58 +01:00
|
|
|
import { Action } from "../../dispatcher/actions";
|
2020-11-02 17:24:47 +00:00
|
|
|
import BaseAvatar from "../views/avatars/BaseAvatar";
|
2021-06-29 13:11:58 +01:00
|
|
|
import { OwnProfileStore } from "../../stores/OwnProfileStore";
|
2022-02-10 10:02:34 +00:00
|
|
|
import AccessibleButton, { ButtonEvent } from "../views/elements/AccessibleButton";
|
2021-06-29 13:11:58 +01:00
|
|
|
import { UPDATE_EVENT } from "../../stores/AsyncStore";
|
|
|
|
|
import { useEventEmitter } from "../../hooks/useEventEmitter";
|
2023-05-23 16:24:12 +01:00
|
|
|
import MatrixClientContext, { useMatrixClientContext } from "../../contexts/MatrixClientContext";
|
2021-06-29 13:11:58 +01:00
|
|
|
import MiniAvatarUploader, { AVATAR_SIZE } from "../views/elements/MiniAvatarUploader";
|
2022-02-10 10:02:34 +00:00
|
|
|
import PosthogTrackers from "../../PosthogTrackers";
|
2022-03-02 16:33:40 -07:00
|
|
|
import EmbeddedPage from "./EmbeddedPage";
|
2020-04-07 10:48:56 +01:00
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
const onClickSendDm = (ev: ButtonEvent): void => {
|
2022-04-26 13:31:53 +02:00
|
|
|
PosthogTrackers.trackInteraction("WebHomeCreateChatButton", ev);
|
2021-06-29 13:11:58 +01:00
|
|
|
dis.dispatch({ action: "view_create_chat" });
|
2020-11-09 14:44:53 +00:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
const onClickExplore = (ev: ButtonEvent): void => {
|
2022-04-26 13:31:53 +02:00
|
|
|
PosthogTrackers.trackInteraction("WebHomeExploreRoomsButton", ev);
|
2020-11-09 14:44:53 +00:00
|
|
|
dis.fire(Action.ViewRoomDirectory);
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
const onClickNewRoom = (ev: ButtonEvent): void => {
|
2022-02-10 10:02:34 +00:00
|
|
|
PosthogTrackers.trackInteraction("WebHomeCreateRoomButton", ev);
|
2021-06-29 13:11:58 +01:00
|
|
|
dis.dispatch({ action: "view_create_room" });
|
2020-11-09 14:44:53 +00:00
|
|
|
};
|
2020-04-07 10:48:56 +01:00
|
|
|
|
2020-11-02 17:24:47 +00:00
|
|
|
interface IProps {
|
|
|
|
|
justRegistered?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
const getOwnProfile = (
|
|
|
|
|
userId: string,
|
|
|
|
|
): {
|
|
|
|
|
displayName: string;
|
2023-02-24 15:28:40 +00:00
|
|
|
avatarUrl?: string;
|
2023-01-12 13:25:14 +00:00
|
|
|
} => ({
|
2020-11-02 17:24:47 +00:00
|
|
|
displayName: OwnProfileStore.instance.displayName || userId,
|
2023-08-24 04:48:35 +01:00
|
|
|
avatarUrl: OwnProfileStore.instance.getHttpAvatarUrl(parseInt(AVATAR_SIZE, 10)) ?? undefined,
|
2020-11-02 17:24:47 +00:00
|
|
|
});
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
const UserWelcomeTop: React.FC = () => {
|
2020-11-02 17:24:47 +00:00
|
|
|
const cli = useContext(MatrixClientContext);
|
2023-02-24 15:28:40 +00:00
|
|
|
const userId = cli.getUserId()!;
|
2020-11-02 17:24:47 +00:00
|
|
|
const [ownProfile, setOwnProfile] = useState(getOwnProfile(userId));
|
|
|
|
|
useEventEmitter(OwnProfileStore.instance, UPDATE_EVENT, () => {
|
|
|
|
|
setOwnProfile(getOwnProfile(userId));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
2020-11-05 15:42:45 +00:00
|
|
|
<MiniAvatarUploader
|
|
|
|
|
hasAvatar={!!ownProfile.avatarUrl}
|
2024-10-18 15:57:39 +01:00
|
|
|
hasAvatarLabel={_t("onboarding|has_avatar_label")}
|
|
|
|
|
noAvatarLabel={_t("onboarding|no_avatar_label")}
|
2020-11-05 15:42:45 +00:00
|
|
|
setAvatarUrl={(url) => cli.setAvatarUrl(url)}
|
2022-05-09 15:10:22 +02:00
|
|
|
isUserAvatar
|
|
|
|
|
onClick={(ev) => PosthogTrackers.trackInteraction("WebHomeMiniAvatarUploadButton", ev)}
|
2020-11-02 17:24:47 +00:00
|
|
|
>
|
|
|
|
|
<BaseAvatar
|
|
|
|
|
idName={userId}
|
|
|
|
|
name={ownProfile.displayName}
|
|
|
|
|
url={ownProfile.avatarUrl}
|
2023-11-29 16:18:29 +00:00
|
|
|
size={AVATAR_SIZE}
|
2020-11-02 17:24:47 +00:00
|
|
|
/>
|
2020-11-05 15:42:45 +00:00
|
|
|
</MiniAvatarUploader>
|
2020-11-02 17:24:47 +00:00
|
|
|
|
2023-09-13 09:30:56 +01:00
|
|
|
<h1>{_tDom("onboarding|welcome_user", { name: ownProfile.displayName })}</h1>
|
|
|
|
|
<h2>{_tDom("onboarding|welcome_detail")}</h2>
|
2020-11-02 17:24:47 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const HomePage: React.FC<IProps> = ({ justRegistered = false }) => {
|
2023-05-23 16:24:12 +01:00
|
|
|
const cli = useMatrixClientContext();
|
2020-04-07 10:48:56 +01:00
|
|
|
const config = SdkConfig.get();
|
2023-05-23 16:24:12 +01:00
|
|
|
const pageUrl = getHomePageUrl(config, cli);
|
2020-04-07 10:48:56 +01:00
|
|
|
|
|
|
|
|
if (pageUrl) {
|
|
|
|
|
return <EmbeddedPage className="mx_HomePage" url={pageUrl} scrollbar={true} />;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-10 11:22:15 +01:00
|
|
|
let introSection: JSX.Element;
|
2023-08-24 04:48:35 +01:00
|
|
|
if (justRegistered || !OwnProfileStore.instance.getHttpAvatarUrl(parseInt(AVATAR_SIZE, 10))) {
|
2020-11-02 17:24:47 +00:00
|
|
|
introSection = <UserWelcomeTop />;
|
|
|
|
|
} else {
|
2022-03-18 10:12:36 -06:00
|
|
|
const brandingConfig = SdkConfig.getObject("branding");
|
|
|
|
|
const logoUrl = brandingConfig?.get("auth_header_logo_url") ?? "themes/element/img/logos/element-logo.svg";
|
2020-11-02 17:24:47 +00:00
|
|
|
|
|
|
|
|
introSection = (
|
|
|
|
|
<React.Fragment>
|
|
|
|
|
<img src={logoUrl} alt={config.brand} />
|
2023-09-13 09:30:56 +01:00
|
|
|
<h1>{_tDom("onboarding|intro_welcome", { appName: config.brand })}</h1>
|
|
|
|
|
<h2>{_tDom("onboarding|intro_byline")}</h2>
|
2020-11-02 17:24:47 +00:00
|
|
|
</React.Fragment>
|
|
|
|
|
);
|
2020-04-07 10:48:56 +01:00
|
|
|
}
|
|
|
|
|
|
2022-08-10 16:29:53 +01:00
|
|
|
return (
|
|
|
|
|
<AutoHideScrollbar className="mx_HomePage mx_HomePage_default" element="main">
|
2020-04-07 10:48:56 +01:00
|
|
|
<div className="mx_HomePage_default_wrapper">
|
2020-11-02 17:24:47 +00:00
|
|
|
{introSection}
|
2020-04-07 10:48:56 +01:00
|
|
|
<div className="mx_HomePage_default_buttons">
|
|
|
|
|
<AccessibleButton onClick={onClickSendDm} className="mx_HomePage_button_sendDm">
|
2023-09-13 09:30:56 +01:00
|
|
|
{_tDom("onboarding|send_dm")}
|
2020-04-07 10:48:56 +01:00
|
|
|
</AccessibleButton>
|
|
|
|
|
<AccessibleButton onClick={onClickExplore} className="mx_HomePage_button_explore">
|
2023-09-13 09:30:56 +01:00
|
|
|
{_tDom("onboarding|explore_rooms")}
|
2020-04-07 10:48:56 +01:00
|
|
|
</AccessibleButton>
|
|
|
|
|
<AccessibleButton onClick={onClickNewRoom} className="mx_HomePage_button_createGroup">
|
2023-09-13 09:30:56 +01:00
|
|
|
{_tDom("onboarding|create_room")}
|
2020-04-07 10:48:56 +01:00
|
|
|
</AccessibleButton>
|
2022-12-12 12:24:14 +01:00
|
|
|
</div>
|
2020-04-07 10:48:56 +01:00
|
|
|
</div>
|
|
|
|
|
</AutoHideScrollbar>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default HomePage;
|