import { observable } from "mobx"; import { observer } from "mobx-react"; import * as React from "react"; import { withTranslation, WithTranslation } from "react-i18next"; import { Switch, Route } from "react-router-dom"; import RootStore from "~/stores/RootStore"; import ErrorSuspended from "~/scenes/ErrorSuspended"; import Layout from "~/components/Layout"; import RegisterKeyDown from "~/components/RegisterKeyDown"; import Sidebar from "~/components/Sidebar"; import SettingsSidebar from "~/components/Sidebar/Settings"; import history from "~/utils/history"; import { searchPath, matchDocumentSlug as slug, newDocumentPath, settingsPath, } from "~/utils/routeHelpers"; import Fade from "./Fade"; import withStores from "./withStores"; const DocumentHistory = React.lazy( () => import( /* webpackChunkName: "document-history" */ "~/components/DocumentHistory" ) ); const CommandBar = React.lazy( () => import( /* webpackChunkName: "command-bar" */ "~/components/CommandBar" ) ); type Props = WithTranslation & RootStore & { children?: React.ReactNode; }; @observer class AuthenticatedLayout extends React.Component { scrollable: HTMLDivElement | null | undefined; @observable keyboardShortcutsOpen = false; goToSearch = (ev: KeyboardEvent) => { if (!ev.metaKey && !ev.ctrlKey) { ev.preventDefault(); ev.stopPropagation(); history.push(searchPath()); } }; goToNewDocument = () => { const { activeCollectionId } = this.props.ui; if (!activeCollectionId) { return; } const can = this.props.policies.abilities(activeCollectionId); if (!can.update) { return; } history.push(newDocumentPath(activeCollectionId)); }; render() { const { auth } = this.props; const { user, team } = auth; const showSidebar = auth.authenticated && user && team; if (auth.isSuspended) { return ; } const sidebar = showSidebar ? ( ) : undefined; const rightRail = ( ); return ( {this.props.children} ); } } export default withTranslation()(withStores(AuthenticatedLayout));