import React, { Component, PropTypes } from 'react' import { find, values } from 'lodash' import Util from '../../Metamaps/Util' const IN_CONVERSATION = 1 // shared with /realtime/reducer.js const MapperList = (props) => { return } class Menu extends Component { constructor(props) { super(props) this.state = { open: false } } toggle = () => { this.setState({ open: !this.state.open }) return true } render = () => { const { currentUser, map, onStar, onRequest, onFollow } = this.props const isFollowing = map.isFollowedBy(currentUser) const style = { display: this.state.open ? 'block' : 'none' } return
} } Menu.propTypes = { currentUser: PropTypes.object.isRequired, map: PropTypes.object.isRequired, onStar: PropTypes.func.isRequired, onRequest: PropTypes.func.isRequired, onFollow: PropTypes.func.isRequired } const Metadata = (props) => { const { map } = props return (
{ map.get('topic_count') }
{ map.get('topic_count') === 1 ? 'topic' : 'topics' }
{ map.get('star_count') }
{ map.get('star_count') === 1 ? 'star' : 'stars' }
{ map.get('synapse_count') }
{ map.get('synapse_count') === 1 ? 'synapse' : 'synapses' }
{ map.get('contributor_count') }
{ map.get('contributor_count') === 1 ? 'contributor' : 'contributors' }
) } const checkAndWrapInA = (shouldWrap, classString, mapId, element) => { if (shouldWrap) return { element } else return element } class MapCard extends Component { render = () => { const { map, mobile, juntoState, currentUser, onRequest, onStar, onFollow } = this.props const hasMap = (juntoState.liveMaps[map.id] && values(juntoState.liveMaps[map.id]).length) || null const realtimeMap = juntoState.liveMaps[map.id] const hasConversation = hasMap && find(values(realtimeMap), v => v === IN_CONVERSATION) const hasMapper = hasMap && !hasConversation const mapperList = hasMap && Object.keys(realtimeMap).map(id => juntoState.connectedPeople[id]) const n = map.get('name') const d = map.get('desc') const maxNameLength = 32 const maxDescLength = 180 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 (
{ checkAndWrapInA(mobile, '', map.id,
{ !mobile &&
}
{ truncatedName }
{ mobile && hasMapper &&
} { mobile && hasConversation &&
} { mobile && d &&
{ d }
} { mobile &&
}
{ map.get('user_name') } { !map.authorizeToEdit(currentUser) &&
View Only
}
{ !mobile && checkAndWrapInA(true, 'mapMetadata', map.id,
{ truncatedDesc }
) } { !mobile && hasMapper &&
} { !mobile && hasConversation &&
} { !mobile && currentUser && }
) }
) } } MapCard.propTypes = { map: PropTypes.object.isRequired, mobile: PropTypes.bool.isRequired, juntoState: PropTypes.object, currentUser: PropTypes.object, onStar: PropTypes.func.isRequired, onRequest: PropTypes.func.isRequired, onFollow: PropTypes.func.isRequired } export default MapCard