import React, { PropTypes } from 'react' import ProfileImage from 'boost/components/ProfileImage' import ModeIcon from 'boost/components/ModeIcon' import moment from 'moment' import { IDLE_MODE, CREATE_MODE, EDIT_MODE, switchArticle, NEW } from '../actions' export default class ArticleList extends React.Component { handleArticleClick (id) { let { dispatch } = this.props return function (e) { dispatch(switchArticle(id)) } } render () { let { status, articles, activeArticle } = this.props let articlesEl = articles.map(article => { let tags = Array.isArray(article.Tags) && article.Tags.length > 0 ? article.Tags.map(tag => { return ( {tag.name} ) }) : ( Not tagged yet ) return (
this.handleArticleClick(article.id)(e)} className={'articleItem' + (activeArticle.id === article.id ? ' active' : '')}>
by {article.User.profileName} {article.status != null ? article.status : moment(article.updatedAt).fromNow()}
{article.status !== NEW ? article.title : '(New article)'}
{tags}
) }) return (
{articlesEl}
) } } ArticleList.propTypes = { status: PropTypes.shape(), articles: PropTypes.array, activeArticle: PropTypes.shape(), dispatch: PropTypes.func }