import React, { Component, PropTypes } from 'react' class MapCard extends Component { render = () => { const { map, currentUser } = this.props function capitalize (string) { return string.charAt(0).toUpperCase() + string.slice(1) } const n = map.get('name') const d = map.get('desc') const maxNameLength = 32 const maxDescLength = 118 const truncatedName = n ? (n.length > maxNameLength ? n.substring(0, maxNameLength) + '...' : n) : '' const truncatedDesc = d ? (d.length > maxDescLength ? d.substring(0, maxDescLength) + '...' : d) : '' const editPermission = map.authorizeToEdit(currentUser) ? 'canEdit' : 'cannotEdit' return (
{ truncatedName }
{ truncatedDesc }
{ map.get('contributor_count') } { map.get('contributor_count') === 1 ? ' contributor' : ' contributors' }
{ map.get('topic_count') } { map.get('topic_count') === 1 ? ' topic' : ' topics' }
{ map.get('permission') ? capitalize(map.get('permission')) : 'Commons' }
{ map.get('synapse_count') } { map.get('synapse_count') === 1 ? ' synapse' : ' synapses' }
) } } MapCard.propTypes = { map: PropTypes.object.isRequired, currentUser: PropTypes.object } export default MapCard