2016-08-21 21:02:49 -04:00
|
|
|
import React, { Component, PropTypes } from 'react'
|
|
|
|
|
|
|
|
class MapCard extends Component {
|
|
|
|
render = () => {
|
|
|
|
const { map, currentUser } = this.props
|
2016-10-08 00:31:32 +08:00
|
|
|
|
2016-08-21 21:02:49 -04:00
|
|
|
function capitalize (string) {
|
|
|
|
return string.charAt(0).toUpperCase() + string.slice(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
const n = map.get('name')
|
|
|
|
const d = map.get('desc')
|
|
|
|
|
|
|
|
const maxNameLength = 32
|
2016-10-16 23:46:55 -04:00
|
|
|
const maxDescLength = 236
|
2016-08-21 21:02:49 -04:00
|
|
|
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'
|
2016-10-08 00:31:32 +08:00
|
|
|
|
2016-08-21 21:02:49 -04:00
|
|
|
return (
|
|
|
|
<div className="map" id={ map.id }>
|
|
|
|
<a href={ '/maps/' + map.id } data-router="true">
|
|
|
|
<div className={ 'permission ' + editPermission }>
|
2016-10-16 23:46:55 -04:00
|
|
|
<div className='mapCard'>
|
|
|
|
<div className='mainContent'>
|
|
|
|
<div className='mapScreenshot'>
|
|
|
|
<img src={ map.get('screenshot_url') } />
|
|
|
|
</div>
|
|
|
|
<div className='title' title={ map.get('name') }>
|
|
|
|
<div className='innerTitle'>{ truncatedName }</div>
|
|
|
|
</div>
|
|
|
|
<div className='creatorAndPerm'>
|
|
|
|
<img className='creatorImage' src={ map.get('user_image') } />
|
|
|
|
<span className='creatorName'>{ map.get('user_name') }</span>
|
2016-08-21 21:02:49 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="mapMetadata">
|
2016-10-16 23:46:55 -04:00
|
|
|
<div className="metadataSection numContributors">
|
|
|
|
{ map.get('contributor_count') }<br/>
|
|
|
|
{ map.get('contributor_count') === 1 ? 'contributor' : 'contributors' }
|
2016-08-21 21:02:49 -04:00
|
|
|
</div>
|
2016-10-16 23:46:55 -04:00
|
|
|
<div className="metadataSection numTopics">
|
|
|
|
{ map.get('topic_count') }<br/>
|
|
|
|
{ map.get('topic_count') === 1 ? 'topic' : 'topics' }
|
2016-08-21 21:02:49 -04:00
|
|
|
</div>
|
2016-10-16 23:46:55 -04:00
|
|
|
<div className="metadataSection numStars">
|
|
|
|
{ map.get('star_count') }<br/>
|
|
|
|
{ map.get('star_count') === 1 ? 'star' : 'stars' }
|
|
|
|
</div>
|
|
|
|
<div className="metadataSection numSynapses">
|
|
|
|
{ map.get('synapse_count') }<br/>
|
|
|
|
{ map.get('synapse_count') === 1 ? 'synapse' : 'synapses' }
|
2016-08-21 21:02:49 -04:00
|
|
|
</div>
|
|
|
|
<div className="clearfloat"></div>
|
2016-10-16 23:46:55 -04:00
|
|
|
<div className="scroll">
|
|
|
|
<div className="desc">
|
|
|
|
{ truncatedDesc }
|
|
|
|
<div className="clearfloat"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-10-08 00:31:32 +08:00
|
|
|
</div>
|
2016-08-21 21:02:49 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MapCard.propTypes = {
|
|
|
|
map: PropTypes.object.isRequired,
|
|
|
|
currentUser: PropTypes.object
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MapCard
|