Moved Layout to be a wrapper for routes

This commit is contained in:
Jori Lallo
2017-06-24 17:14:36 -07:00
parent aa0ddd94bf
commit b8d0666c63
11 changed files with 211 additions and 222 deletions

View File

@ -154,8 +154,12 @@ const MenuLink = styled(Link)`
`; `;
const Content = styled(Flex)` const Content = styled(Flex)`
height: 100%;
overflow: scroll; overflow: scroll;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 250px;
`; `;
const Sidebar = styled(Flex)` const Sidebar = styled(Flex)`

View File

@ -31,6 +31,8 @@ import Flatpage from 'scenes/Flatpage';
import ErrorAuth from 'scenes/ErrorAuth'; import ErrorAuth from 'scenes/ErrorAuth';
import Error404 from 'scenes/Error404'; import Error404 from 'scenes/Error404';
import Layout from 'components/Layout';
import flatpages from 'static/flatpages'; import flatpages from 'static/flatpages';
let DevTools; let DevTools;
@ -94,6 +96,7 @@ render(
<Route exact path="/auth/error" component={ErrorAuth} /> <Route exact path="/auth/error" component={ErrorAuth} />
<Auth> <Auth>
<Layout>
<Switch> <Switch>
<Route exact path="/dashboard" component={Dashboard} /> <Route exact path="/dashboard" component={Dashboard} />
<Route exact path="/collections/:id" component={Collection} /> <Route exact path="/collections/:id" component={Collection} />
@ -121,6 +124,7 @@ render(
<Route path="/404" component={Error404} /> <Route path="/404" component={Error404} />
<Route component={notFoundSearch} /> <Route component={notFoundSearch} />
</Switch> </Switch>
</Layout>
</Auth> </Auth>
</Switch> </Switch>
</Router> </Router>

View File

@ -7,7 +7,6 @@ import _ from 'lodash';
import CollectionsStore from 'stores/CollectionsStore'; import CollectionsStore from 'stores/CollectionsStore';
import CollectionStore from './CollectionStore'; import CollectionStore from './CollectionStore';
import Layout from 'components/Layout';
import CenteredContent from 'components/CenteredContent'; import CenteredContent from 'components/CenteredContent';
import PreviewLoading from 'components/PreviewLoading'; import PreviewLoading from 'components/PreviewLoading';
@ -31,15 +30,11 @@ type Props = {
}; };
render() { render() {
return ( return this.store.redirectUrl
<Layout>
{this.store.redirectUrl
? <Redirect to={this.store.redirectUrl} /> ? <Redirect to={this.store.redirectUrl} />
: <CenteredContent> : <CenteredContent>
<PreviewLoading /> <PreviewLoading />
</CenteredContent>} </CenteredContent>;
</Layout>
);
} }
} }
export default inject('collections')(Collection); export default inject('collections')(Collection);

View File

@ -5,7 +5,6 @@ import { Flex } from 'reflexbox';
import CollectionsStore from 'stores/CollectionsStore'; import CollectionsStore from 'stores/CollectionsStore';
import Layout from 'components/Layout';
import Collection from 'components/Collection'; import Collection from 'components/Collection';
import PreviewLoading from 'components/PreviewLoading'; import PreviewLoading from 'components/PreviewLoading';
import CenteredContent from 'components/CenteredContent'; import CenteredContent from 'components/CenteredContent';
@ -21,7 +20,6 @@ type Props = {
const { collections } = this.props; const { collections } = this.props;
return ( return (
<Layout>
<CenteredContent> <CenteredContent>
<Flex column auto> <Flex column auto>
{!collections.isLoaded {!collections.isLoaded
@ -31,7 +29,6 @@ type Props = {
))} ))}
</Flex> </Flex>
</CenteredContent> </CenteredContent>
</Layout>
); );
} }
} }

View File

@ -9,10 +9,9 @@ import { Flex } from 'reflexbox';
import UiStore from 'stores/UiStore'; import UiStore from 'stores/UiStore';
import DocumentStore from './DocumentStore'; import DocumentStore from './DocumentStore';
import Breadcrumbs from './components/Breadcrumbs'; // import Menu from './components/Menu';
import Menu from './components/Menu';
import Editor from 'components/Editor'; import Editor from 'components/Editor';
import Layout, { HeaderAction, SaveAction } from 'components/Layout'; // import { HeaderAction, SaveAction } from 'components/Layout';
import PublishingInfo from 'components/PublishingInfo'; import PublishingInfo from 'components/PublishingInfo';
import PreviewLoading from 'components/PreviewLoading'; import PreviewLoading from 'components/PreviewLoading';
import CenteredContent from 'components/CenteredContent'; import CenteredContent from 'components/CenteredContent';
@ -47,9 +46,11 @@ type Props = {
if (this.props.newDocument) { if (this.props.newDocument) {
this.store.collectionId = this.props.match.params.id; this.store.collectionId = this.props.match.params.id;
this.store.newDocument = true; this.store.newDocument = true;
this.props.ui.enableEditMode();
} else if (this.props.match.params.edit) { } else if (this.props.match.params.edit) {
this.store.documentId = this.props.match.params.id; this.store.documentId = this.props.match.params.id;
this.store.fetchDocument(); this.store.fetchDocument();
this.props.ui.enableEditMode();
} else if (this.props.newChildDocument) { } else if (this.props.newChildDocument) {
this.store.documentId = this.props.match.params.id; this.store.documentId = this.props.match.params.id;
this.store.newChildDocument = true; this.store.newChildDocument = true;
@ -76,6 +77,7 @@ type Props = {
} else { } else {
this.store.updateDocument(options); this.store.updateDocument(options);
} }
this.props.ui.disableEditMode();
}; };
onImageUploadStart = () => { onImageUploadStart = () => {
@ -91,18 +93,18 @@ type Props = {
}; };
render() { render() {
const isNew = this.props.newDocument || this.props.newChildDocument; // const isNew = this.props.newDocument || this.props.newChildDocument;
const isEditing = this.props.match.params.edit; const isEditing = this.props.match.params.edit;
const title = ( /*const title = (
<Breadcrumbs <Breadcrumbs
document={this.store.document} document={this.store.document}
pathToDocument={this.store.pathToDocument} pathToDocument={this.store.pathToDocument}
/> />
); );*/
const titleText = this.store.document && get(this.store, 'document.title'); const titleText = this.store.document && get(this.store, 'document.title');
const actions = ( /*const actions = (
<Flex> <Flex>
<HeaderAction> <HeaderAction>
{isEditing {isEditing
@ -115,22 +117,18 @@ type Props = {
</HeaderAction> </HeaderAction>
<Menu store={this.store} document={this.store.document} /> <Menu store={this.store} document={this.store.document} />
</Flex> </Flex>
); );*/
// actions={actions}
// title={title}
// loading={this.store.isSaving || this.store.isUploading}
// search={false}
// fixed
return ( return (
<Layout
actions={actions}
title={title}
loading={this.store.isSaving || this.store.isUploading}
search={false}
fixed
>
<PagePadding> <PagePadding>
<PageTitle title={titleText} /> <PageTitle title={titleText} />
<Prompt <Prompt when={this.store.hasPendingChanges} message={DISCARD_CHANGES} />
when={this.store.hasPendingChanges}
message={DISCARD_CHANGES}
/>
{this.store.isFetching && {this.store.isFetching &&
<CenteredContent> <CenteredContent>
<PreviewLoading /> <PreviewLoading />
@ -156,7 +154,6 @@ type Props = {
/> />
</Container>} </Container>}
</PagePadding> </PagePadding>
</Layout>
); );
} }
} }

View File

@ -2,23 +2,20 @@
import React from 'react'; import React from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import Layout from 'components/Layout';
import CenteredContent from 'components/CenteredContent'; import CenteredContent from 'components/CenteredContent';
import PageTitle from 'components/PageTitle'; import PageTitle from 'components/PageTitle';
class Error404 extends React.Component { class Error404 extends React.Component {
render() { render() {
return ( return (
<Layout>
<PageTitle title="Not found" />
<CenteredContent> <CenteredContent>
<PageTitle title="Not found" />
<h1>Not Found</h1> <h1>Not Found</h1>
<p>We're unable to find the page you're accessing.</p> <p>We're unable to find the page you're accessing.</p>
<p>Maybe you want to try <Link to="/search">search</Link> instead?</p> <p>Maybe you want to try <Link to="/search">search</Link> instead?</p>
</CenteredContent> </CenteredContent>
</Layout>
); );
} }
} }

View File

@ -2,23 +2,20 @@
import React from 'react'; import React from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import Layout from 'components/Layout';
import CenteredContent from 'components/CenteredContent'; import CenteredContent from 'components/CenteredContent';
import PageTitle from 'components/PageTitle'; import PageTitle from 'components/PageTitle';
class ErrorAuth extends React.Component { class ErrorAuth extends React.Component {
render() { render() {
return ( return (
<Layout>
<PageTitle title="Authentication error" />
<CenteredContent> <CenteredContent>
<PageTitle title="Authentication error" />
<h1>Authentication failed</h1> <h1>Authentication failed</h1>
<p> <p>
We were unable to log you in. <Link to="/">Please try again.</Link> We were unable to log you in. <Link to="/">Please try again.</Link>
</p> </p>
</CenteredContent> </CenteredContent>
</Layout>
); );
} }
} }

View File

@ -7,7 +7,6 @@ import styled from 'styled-components';
import AuthStore from 'stores/AuthStore'; import AuthStore from 'stores/AuthStore';
import Layout from 'components/Layout';
import CenteredContent from 'components/CenteredContent'; import CenteredContent from 'components/CenteredContent';
import SlackAuthLink from 'components/SlackAuthLink'; import SlackAuthLink from 'components/SlackAuthLink';
import Alert from 'components/Alert'; import Alert from 'components/Alert';
@ -40,7 +39,6 @@ type Props = {
return ( return (
<Flex auto> <Flex auto>
<Layout notifications={this.notifications}>
{this.props.auth.authenticated && <Redirect to="/dashboard" />} {this.props.auth.authenticated && <Redirect to="/dashboard" />}
<CenteredContent> <CenteredContent>
@ -63,7 +61,6 @@ type Props = {
</SlackAuthLink> </SlackAuthLink>
</div> </div>
</CenteredContent> </CenteredContent>
</Layout>
</Flex> </Flex>
); );
} }

View File

@ -12,7 +12,6 @@ import ArrowKeyNavigation from 'boundless-arrow-key-navigation';
import SearchField from './components/SearchField'; import SearchField from './components/SearchField';
import SearchStore from './SearchStore'; import SearchStore from './SearchStore';
import Layout, { Title } from 'components/Layout';
import CenteredContent from 'components/CenteredContent'; import CenteredContent from 'components/CenteredContent';
import DocumentPreview from 'components/DocumentPreview'; import DocumentPreview from 'components/DocumentPreview';
import PageTitle from 'components/PageTitle'; import PageTitle from 'components/PageTitle';
@ -83,13 +82,11 @@ const ResultsWrapper = styled(Flex)`
render() { render() {
const query = this.props.match.params.query; const query = this.props.match.params.query;
const title = <Title content="Search" />;
const hasResults = this.store.documents.length > 0; const hasResults = this.store.documents.length > 0;
return ( return (
<Layout title={title} search={false} loading={this.store.isFetching}>
<PageTitle title="Search" />
<Container auto> <Container auto>
<PageTitle title="Search" />
{this.props.notFound && {this.props.notFound &&
<div> <div>
<h1>Not Found</h1> <h1>Not Found</h1>
@ -117,7 +114,6 @@ const ResultsWrapper = styled(Flex)`
</ArrowKeyNavigation> </ArrowKeyNavigation>
</ResultsWrapper> </ResultsWrapper>
</Container> </Container>
</Layout>
); );
} }
} }

View File

@ -8,7 +8,6 @@ import ApiKeyRow from './components/ApiKeyRow';
import styles from './Settings.scss'; import styles from './Settings.scss';
import SettingsStore from './SettingsStore'; import SettingsStore from './SettingsStore';
import Layout, { Title } from 'components/Layout';
import CenteredContent from 'components/CenteredContent'; import CenteredContent from 'components/CenteredContent';
import SlackAuthLink from 'components/SlackAuthLink'; import SlackAuthLink from 'components/SlackAuthLink';
import PageTitle from 'components/PageTitle'; import PageTitle from 'components/PageTitle';
@ -22,13 +21,11 @@ import PageTitle from 'components/PageTitle';
} }
render() { render() {
const title = <Title content="Settings" />;
const showSlackSettings = DEPLOYMENT === 'hosted'; const showSlackSettings = DEPLOYMENT === 'hosted';
return ( return (
<Layout title={title} search={false} loading={this.store.isFetching}>
<PageTitle title="Settings" />
<CenteredContent> <CenteredContent>
<PageTitle title="Settings" />
{showSlackSettings && {showSlackSettings &&
<div className={styles.section}> <div className={styles.section}>
<h2 className={styles.sectionHeader}>Slack</h2> <h2 className={styles.sectionHeader}>Slack</h2>
@ -87,7 +84,6 @@ import PageTitle from 'components/PageTitle';
</div> </div>
</div> </div>
</CenteredContent> </CenteredContent>
</Layout>
); );
} }
} }

View File

@ -3,6 +3,7 @@ import { observable, action } from 'mobx';
class UiStore { class UiStore {
@observable activeCollection: ?string; @observable activeCollection: ?string;
@observable editMode: boolean = false;
/* Actions */ /* Actions */
@ -13,6 +14,14 @@ class UiStore {
@action clearActiveCollection = (): void => { @action clearActiveCollection = (): void => {
this.activeCollection = null; this.activeCollection = null;
}; };
@action enableEditMode() {
this.editMode = true;
}
@action disableEditMode() {
this.editMode = false;
}
} }
export default UiStore; export default UiStore;