/* Copyright 2020 The Matrix.org Foundation C.I.C. 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. */ import * as React from "react"; import {useContext, useRef, useState} from "react"; import AutoHideScrollbar from './AutoHideScrollbar'; import {getHomePageUrl} from "../../utils/pages"; import {_t} from "../../languageHandler"; import SdkConfig from "../../SdkConfig"; import * as sdk from "../../index"; import dis from "../../dispatcher/dispatcher"; import {Action} from "../../dispatcher/actions"; import {Transition} from "react-transition-group"; import BaseAvatar from "../views/avatars/BaseAvatar"; import {OwnProfileStore} from "../../stores/OwnProfileStore"; import AccessibleButton from "../views/elements/AccessibleButton"; import Tooltip from "../views/elements/Tooltip"; import {UPDATE_EVENT} from "../../stores/AsyncStore"; import {useEventEmitter} from "../../hooks/useEventEmitter"; import MatrixClientContext from "../../contexts/MatrixClientContext"; import classNames from "classnames"; import {ENTERING} from "react-transition-group/Transition"; const onClickSendDm = () => dis.dispatch({action: 'view_create_chat'}); const onClickExplore = () => dis.fire(Action.ViewRoomDirectory); const onClickNewRoom = () => dis.dispatch({action: 'view_create_room'}); interface IProps { justRegistered?: boolean; } const avatarSize = 52; const getOwnProfile = (userId: string) => ({ displayName: OwnProfileStore.instance.displayName || userId, avatarUrl: OwnProfileStore.instance.getHttpAvatarUrl(avatarSize), }); const UserWelcomeTop = () => { const cli = useContext(MatrixClientContext); const userId = cli.getUserId(); const [ownProfile, setOwnProfile] = useState(getOwnProfile(userId)); useEventEmitter(OwnProfileStore.instance, UPDATE_EVENT, () => { setOwnProfile(getOwnProfile(userId)); }); const [busy, setBusy] = useState(false); const uploadRef = useRef(); return
{ if (!ev.target.files?.length) return; setBusy(true); const file = ev.target.files[0]; const uri = await cli.uploadContent(file); await cli.setAvatarUrl(uri); setBusy(false); }} accept="image/*" /> { uploadRef.current.click(); }} > {state => ( )}

{ _t("Welcome %(name)s", { name: ownProfile.displayName }) }

{ _t("Now, lets help you get started") }

; }; const HomePage: React.FC = ({ justRegistered = false }) => { const config = SdkConfig.get(); const pageUrl = getHomePageUrl(config); if (pageUrl) { const EmbeddedPage = sdk.getComponent('structures.EmbeddedPage'); return ; } let introSection; if (justRegistered) { introSection = ; } else { const brandingConfig = config.branding; let logoUrl = "themes/element/img/logos/element-logo.svg"; if (brandingConfig && brandingConfig.authHeaderLogoUrl) { logoUrl = brandingConfig.authHeaderLogoUrl; } introSection = {config.brand}

{ _t("Welcome to %(appName)s", { appName: config.brand }) }

{ _t("Liberate your communication") }

; } return
{ introSection }
{ _t("Send a Direct Message") } { _t("Explore Public Rooms") } { _t("Create a Group Chat") }
; }; export default HomePage;