Migrated document preview into its own component

This commit is contained in:
Jori Lallo
2016-05-20 09:02:39 -07:00
parent 01bd07bf9b
commit db25564a82
5 changed files with 54 additions and 27 deletions

View File

@@ -1,7 +1,8 @@
import React from 'react';
import moment from 'moment';
import Link from 'react-router/lib/Link';
import DocumentPreview from 'components/DocumentPreview';
import styles from './AtlasPreview.scss';
import classNames from 'classnames/bind';
const cx = classNames.bind(styles);
@@ -20,10 +21,7 @@ class AtlasPreview extends React.Component {
{ data.recentDocuments.length > 0 ?
data.recentDocuments.map(document => {
return (
<Link to={ `/documents/${document.id}` } className={ styles.documentPreview }>
<h3>{ document.title }</h3>
<span>{ moment(document.updatedAt).fromNow() }</span>
</Link>)
<DocumentPreview document={ document } />)
})
: (
<div className={ styles.description }>No documents. Why not <Link to={ `/atlas/${data.id}/new` }>create one</Link>?</div>

View File

@@ -17,25 +17,3 @@
.description {
color: #aaa;
}
.documentPreview {
display: flex;
flex: 1;
justify-content: space-between;
margin-bottom: 20px;
text-decoration: none;
h3 {
font-weight: normal;
font-size: 15px;
color: $textColor;
margin: 0;
}
span {
font-size: 13px;
color: #ccc;
}
}

View File

@@ -0,0 +1,26 @@
import React from 'react';
import moment from 'moment';
import Link from 'react-router/lib/Link';
import styles from './documentPreview.scss';
import classNames from 'classnames/bind';
const cx = classNames.bind(styles);
class documentPreview extends React.Component {
static propTypes = {
document: React.PropTypes.object.isRequired,
}
render() {
const document = this.props.document;
return (
<Link to={ `/documents/${document.id}` } className={ styles.documentPreview }>
<h3>{ document.title }</h3>
<span>{ moment(document.updatedAt).fromNow() }</span>
</Link>
);
}
};
export default documentPreview;

View File

@@ -0,0 +1,23 @@
@import '../../utils/constants.scss';
.documentPreview {
display: flex;
flex: 1;
justify-content: space-between;
margin-bottom: 20px;
text-decoration: none;
}
h3 {
font-weight: normal;
font-size: 15px;
color: $textColor;
margin: 0;
}
span {
font-size: 13px;
color: #ccc;
}

View File

@@ -0,0 +1,2 @@
import DocumentPreview from './DocumentPreview';
export default DocumentPreview;