This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
outline/app/components/Layout.js
Tom Moor 642c11ff7d Document Archive (#921)
* WIP: Archive

* WIP

* Finishing up archive endpoints

* WIP

* Update docs

* Flow

* Stash

* Add toast message confirmations

* Redirect handling, fixed publishhing info for archived docs

* Redirect to collection instead of home, remove unused pub info

* Account for deleted parent

* Trash -> Archive
Allow reading of archived docs

* Dont overload deletedAt

* Fixes

* 💚

* ParentDocumentId wipe for unarchived sub docs

* Fix: CMD+S exits editing
Fix: Duplicate user name on published but unedited docs

* Improve jank on paginated lists

* Prevent editing when archived

* 💚
Separate lint / flow steps
2019-04-06 16:20:27 -07:00

148 lines
3.7 KiB
JavaScript

// @flow
import * as React from 'react';
import { Switch, Route, Redirect } from 'react-router-dom';
import { Helmet } from 'react-helmet';
import styled, { withTheme } from 'styled-components';
import breakpoint from 'styled-components-breakpoint';
import { observable } from 'mobx';
import { observer, inject } from 'mobx-react';
import keydown from 'react-keydown';
import Analytics from 'components/Analytics';
import Flex from 'shared/components/Flex';
import {
homeUrl,
searchUrl,
matchDocumentSlug as slug,
} from 'utils/routeHelpers';
import { LoadingIndicatorBar } from 'components/LoadingIndicator';
import { GlobalStyles } from 'components/DropToImport';
import Sidebar from 'components/Sidebar';
import SettingsSidebar from 'components/Sidebar/Settings';
import Modals from 'components/Modals';
import DocumentHistory from 'components/DocumentHistory';
import ErrorSuspended from 'scenes/ErrorSuspended';
import AuthStore from 'stores/AuthStore';
import UiStore from 'stores/UiStore';
import DocumentsStore from 'stores/DocumentsStore';
type Props = {
documents: DocumentsStore,
children?: ?React.Node,
actions?: ?React.Node,
title?: ?React.Node,
auth: AuthStore,
ui: UiStore,
notifications?: React.Node,
theme: Object,
};
@observer
class Layout extends React.Component<Props> {
scrollable: ?HTMLDivElement;
@observable redirectTo: ?string;
componentWillMount() {
this.updateBackground();
}
componentDidUpdate() {
this.updateBackground();
if (this.redirectTo) {
this.redirectTo = undefined;
}
}
updateBackground() {
// ensure the wider page color always matches the theme
window.document.body.style.background = this.props.theme.background;
}
@keydown(['/', 't', 'meta+k'])
goToSearch(ev) {
ev.preventDefault();
ev.stopPropagation();
this.redirectTo = searchUrl();
}
@keydown('d')
goToDashboard() {
this.redirectTo = homeUrl();
}
@keydown('shift+/')
openKeyboardShortcuts() {
this.props.ui.setActiveModal('keyboard-shortcuts');
}
render() {
const { auth, ui } = this.props;
const { user, team } = auth;
const showSidebar = auth.authenticated && user && team;
if (auth.isSuspended) return <ErrorSuspended />;
if (this.redirectTo) return <Redirect to={this.redirectTo} push />;
return (
<Container column auto>
<Helmet>
<title>Outline</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
</Helmet>
<Analytics />
{this.props.ui.progressBarVisible && <LoadingIndicatorBar />}
{this.props.notifications}
<Container auto>
{showSidebar && (
<Switch>
<Route path="/settings" component={SettingsSidebar} />
<Route component={Sidebar} />
</Switch>
)}
<Content auto justify="center" editMode={ui.editMode}>
{this.props.children}
</Content>
<Switch>
<Route
path={`/doc/${slug}/history/:revisionId?`}
component={DocumentHistory}
/>
</Switch>
</Container>
<Modals ui={ui} />
<GlobalStyles />
</Container>
);
}
}
const Container = styled(Flex)`
background: ${props => props.theme.background};
position: relative;
width: 100vw;
min-height: 100%;
`;
const Content = styled(Flex)`
margin: 0;
transition: margin-left 100ms ease-out;
@media print {
margin: 0;
}
${breakpoint('tablet')`
margin-left: ${props => (props.editMode ? 0 : props.theme.sidebarWidth)};
`};
`;
export default inject('auth', 'ui', 'documents')(withTheme(Layout));