From 8f45e06844a202078c7d5b8325a77e7693ee965a Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 16 Jun 2020 08:46:48 -0600 Subject: [PATCH] Add a home button to the new room list menu when available --- src/components/structures/UserMenuButton.tsx | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/components/structures/UserMenuButton.tsx b/src/components/structures/UserMenuButton.tsx index 41b2c3ab60..f3626ba270 100644 --- a/src/components/structures/UserMenuButton.tsx +++ b/src/components/structures/UserMenuButton.tsx @@ -32,6 +32,8 @@ import SettingsStore, {SettingLevel} from "../../settings/SettingsStore"; import {getCustomTheme} from "../../theme"; import {getHostingLink} from "../../utils/HostingLink"; import AccessibleButton, {ButtonEvent} from "../views/elements/AccessibleButton"; +import SdkConfig from "../../SdkConfig"; +import {getHomePageUrl} from "../../utils/pages"; interface IProps { } @@ -67,6 +69,10 @@ export default class UserMenuButton extends React.Component { } } + private get hasHomePage(): boolean { + return !!getHomePageUrl(SdkConfig.get()); + } + public componentDidMount() { this.dispatcherRef = defaultDispatcher.register(this.onAction); this.themeWatcherRef = SettingsStore.watchSetting("theme", null, this.onThemeChanged); @@ -147,6 +153,13 @@ export default class UserMenuButton extends React.Component { this.setState({menuDisplayed: false}); // also close the menu }; + private onHomeClick = (ev: ButtonEvent) => { + ev.preventDefault(); + ev.stopPropagation(); + + defaultDispatcher.dispatch({action: 'view_home_page'}); + }; + public render() { let contextMenu; if (this.state.menuDisplayed) { @@ -172,6 +185,18 @@ export default class UserMenuButton extends React.Component { ); } + let homeButton = null; + if (this.hasHomePage) { + homeButton = ( +
  • + + + {_t("Home")} + +
  • + ); + } + const elementRect = this.buttonRef.current.getBoundingClientRect(); contextMenu = ( { {hostingLink}
      + {homeButton}
    • this.onSettingsOpen(e, USER_NOTIFICATIONS_TAB)}>