import PropTypes from 'prop-types'; import React from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import moment from 'moment'; import { Link, browserHistory } from 'react-router'; import InlineSVG from 'react-inlinesvg'; import * as SketchActions from '../actions/projects'; import * as ProjectActions from '../actions/project'; import * as ToastActions from '../actions/toast'; const trashCan = require('../../../images/trash-can.svg'); class SketchList extends React.Component { constructor(props) { super(props); this.props.getProjects(this.props.username); } render() { const username = this.props.username !== undefined ? this.props.username : this.props.user.username; return (
{ this.props.sketches.length === 0 &&

No sketches.

} { this.props.sketches.length > 0 && {this.props.sketches.map(sketch => // eslint-disable-next-line browserHistory.push(`/${username}/sketches/${sketch.id}`)} > )}
Sketch Date created Date updated
{(() => { // eslint-disable-line if (this.props.username === this.props.user.username || this.props.username === undefined) { return ( ); } })()} {sketch.name} {moment(sketch.createdAt).format('MMM D, YYYY h:mm A')} {moment(sketch.updatedAt).format('MMM D, YYYY h:mm A')}
}
); } } SketchList.propTypes = { user: PropTypes.shape({ username: PropTypes.string }).isRequired, getProjects: PropTypes.func.isRequired, sketches: PropTypes.arrayOf(PropTypes.shape({ id: PropTypes.string.isRequired, name: PropTypes.string.isRequired, createdAt: PropTypes.string.isRequired, updatedAt: PropTypes.string.isRequired })).isRequired, username: PropTypes.string, deleteProject: PropTypes.func.isRequired }; SketchList.defaultProps = { username: undefined }; function mapStateToProps(state) { return { user: state.user, sketches: state.sketches }; } function mapDispatchToProps(dispatch) { return bindActionCreators(Object.assign({}, SketchActions, ProjectActions, ToastActions), dispatch); } export default connect(mapStateToProps, mapDispatchToProps)(SketchList);