Upgraded dependencies
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
import React, { PropTypes } from 'react';
|
||||
import { Link, browserHistory } from 'react-router';
|
||||
import { observer } from 'mobx-react';
|
||||
import { observer, inject } from 'mobx-react';
|
||||
import { toJS } from 'mobx';
|
||||
import keydown from 'react-keydown';
|
||||
import _ from 'lodash';
|
||||
|
||||
import DocumentSceneStore, {
|
||||
DOCUMENT_PREFERENCES,
|
||||
} from './DocumentSceneStore';
|
||||
import DocumentSceneStore, { DOCUMENT_PREFERENCES } from './DocumentSceneStore';
|
||||
|
||||
import Layout from 'components/Layout';
|
||||
import AtlasPreviewLoading from 'components/AtlasPreviewLoading';
|
||||
@@ -22,7 +20,8 @@ import styles from './DocumentScene.scss';
|
||||
// const cx = classNames.bind(styles);
|
||||
|
||||
@keydown(['cmd+/', 'ctrl+/', 'c', 'e'])
|
||||
@observer(['ui', 'cache'])
|
||||
@inject('ui', 'cache')
|
||||
@observer
|
||||
class DocumentScene extends React.Component {
|
||||
static propTypes = {
|
||||
ui: PropTypes.object.isRequired,
|
||||
@@ -30,7 +29,7 @@ class DocumentScene extends React.Component {
|
||||
routeParams: PropTypes.object,
|
||||
params: PropTypes.object.isRequired,
|
||||
location: PropTypes.object.isRequired,
|
||||
}
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@@ -44,7 +43,7 @@ class DocumentScene extends React.Component {
|
||||
|
||||
state = {
|
||||
didScroll: false,
|
||||
}
|
||||
};
|
||||
|
||||
componentDidMount = async () => {
|
||||
const { id } = this.props.routeParams;
|
||||
@@ -52,9 +51,9 @@ class DocumentScene extends React.Component {
|
||||
replaceUrl: !this.props.location.hash,
|
||||
});
|
||||
this.scrollTohash();
|
||||
}
|
||||
};
|
||||
|
||||
componentWillReceiveProps = async (nextProps) => {
|
||||
componentWillReceiveProps = async nextProps => {
|
||||
const key = nextProps.keydown.event;
|
||||
if (key) {
|
||||
if (key.key === '/' && (key.metaKey || key.ctrl.Key)) {
|
||||
@@ -81,25 +80,26 @@ class DocumentScene extends React.Component {
|
||||
}
|
||||
|
||||
this.scrollTohash();
|
||||
}
|
||||
};
|
||||
|
||||
onEdit = () => {
|
||||
const url = `${this.store.document.url}/edit`;
|
||||
browserHistory.push(url);
|
||||
}
|
||||
};
|
||||
|
||||
onCreateDocument = () => {
|
||||
browserHistory.push(`${this.store.collectionTree.url}/new`);
|
||||
}
|
||||
};
|
||||
|
||||
onCreateChild = () => {
|
||||
browserHistory.push(`${this.store.document.url}/new`);
|
||||
}
|
||||
};
|
||||
|
||||
onDelete = () => {
|
||||
let msg;
|
||||
if (this.store.document.collection.type === 'atlas') {
|
||||
msg = 'Are you sure you want to delete this document and all it\'s child documents (if any)?';
|
||||
msg =
|
||||
"Are you sure you want to delete this document and all it's child documents (if any)?";
|
||||
} else {
|
||||
msg = 'Are you sure you want to delete this document?';
|
||||
}
|
||||
@@ -107,7 +107,7 @@ class DocumentScene extends React.Component {
|
||||
if (confirm(msg)) {
|
||||
this.store.deleteDocument();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
onExport = () => {
|
||||
const doc = this.store.document;
|
||||
@@ -116,7 +116,7 @@ class DocumentScene extends React.Component {
|
||||
a.download = `${doc.title}.md`;
|
||||
a.href = `data:text/markdown;charset=UTF-8,${encodeURIComponent(doc.text)}`;
|
||||
a.click();
|
||||
}
|
||||
};
|
||||
|
||||
scrollTohash = () => {
|
||||
// Scroll to anchor after loading, and only once
|
||||
@@ -128,40 +128,41 @@ class DocumentScene extends React.Component {
|
||||
const element = window.document.getElementsByName(name)[0];
|
||||
if (element) element.scrollIntoView();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const {
|
||||
sidebar,
|
||||
} = this.props.ui;
|
||||
const { sidebar } = this.props.ui;
|
||||
|
||||
const doc = this.store.document;
|
||||
const allowDelete = doc && doc.collection.type === 'atlas' &&
|
||||
const allowDelete =
|
||||
doc &&
|
||||
doc.collection.type === 'atlas' &&
|
||||
doc.id !== doc.collection.navigationTree.id;
|
||||
let title;
|
||||
let titleText;
|
||||
let actions;
|
||||
if (doc) {
|
||||
actions = (
|
||||
<div className={ styles.actions }>
|
||||
<DropdownMenu label={ <MoreIcon /> }>
|
||||
{ this.store.isCollection && (
|
||||
<div className={ styles.menuGroup }>
|
||||
<MenuItem onClick={ this.onCreateDocument }>New document</MenuItem>
|
||||
<MenuItem onClick={ this.onCreateChild }>New child</MenuItem>
|
||||
</div>
|
||||
) }
|
||||
<MenuItem onClick={ this.onEdit }>Edit</MenuItem>
|
||||
<MenuItem onClick={ this.onExport }>Export</MenuItem>
|
||||
{ allowDelete && <MenuItem onClick={ this.onDelete }>Delete</MenuItem> }
|
||||
<div className={styles.actions}>
|
||||
<DropdownMenu label={<MoreIcon />}>
|
||||
{this.store.isCollection &&
|
||||
<div className={styles.menuGroup}>
|
||||
<MenuItem onClick={this.onCreateDocument}>
|
||||
New document
|
||||
</MenuItem>
|
||||
<MenuItem onClick={this.onCreateChild}>New child</MenuItem>
|
||||
</div>}
|
||||
<MenuItem onClick={this.onEdit}>Edit</MenuItem>
|
||||
<MenuItem onClick={this.onExport}>Export</MenuItem>
|
||||
{allowDelete && <MenuItem onClick={this.onDelete}>Delete</MenuItem>}
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
);
|
||||
title = (
|
||||
<span>
|
||||
/
|
||||
<Link to={ doc.collection.url }>{ doc.collection.name }</Link>
|
||||
{ ` / ${doc.title}` }
|
||||
<Link to={doc.collection.url}>{doc.collection.name}</Link>
|
||||
{` / ${doc.title}`}
|
||||
</span>
|
||||
);
|
||||
titleText = `${doc.collection.name} - ${doc.title}`;
|
||||
@@ -169,33 +170,30 @@ class DocumentScene extends React.Component {
|
||||
|
||||
return (
|
||||
<Layout
|
||||
title={ title }
|
||||
titleText={ titleText }
|
||||
actions={ doc && actions }
|
||||
loading={ this.store.updatingStructure }
|
||||
title={title}
|
||||
titleText={titleText}
|
||||
actions={doc && actions}
|
||||
loading={this.store.updatingStructure}
|
||||
>
|
||||
{ this.store.isFetching ? (
|
||||
<CenteredContent>
|
||||
<AtlasPreviewLoading />
|
||||
</CenteredContent>
|
||||
) : (
|
||||
<Flex auto>
|
||||
{ this.store.isCollection && (
|
||||
<Sidebar
|
||||
open={ sidebar }
|
||||
onToggle={ this.props.ui.toggleSidebar }
|
||||
navigationTree={ toJS(this.store.collectionTree) }
|
||||
onNavigationUpdate={ this.store.updateNavigationTree }
|
||||
onNodeCollapse={ this.store.onNodeCollapse }
|
||||
/>
|
||||
) }
|
||||
<Flex auto justify="center" className={ styles.content }>
|
||||
<CenteredContent>
|
||||
<Document document={ doc } />
|
||||
</CenteredContent>
|
||||
</Flex>
|
||||
</Flex>
|
||||
) }
|
||||
{this.store.isFetching
|
||||
? <CenteredContent>
|
||||
<AtlasPreviewLoading />
|
||||
</CenteredContent>
|
||||
: <Flex auto>
|
||||
{this.store.isCollection &&
|
||||
<Sidebar
|
||||
open={sidebar}
|
||||
onToggle={this.props.ui.toggleSidebar}
|
||||
navigationTree={toJS(this.store.collectionTree)}
|
||||
onNavigationUpdate={this.store.updateNavigationTree}
|
||||
onNodeCollapse={this.store.onNodeCollapse}
|
||||
/>}
|
||||
<Flex auto justify="center" className={styles.content}>
|
||||
<CenteredContent>
|
||||
<Document document={doc} />
|
||||
</CenteredContent>
|
||||
</Flex>
|
||||
</Flex>}
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user