2017-03-07 03:49:46 +00:00
|
|
|
import React, { PropTypes, Component } from 'react'
|
2017-03-22 16:09:47 +00:00
|
|
|
import Draggable from 'react-draggable'
|
2017-03-07 03:49:46 +00:00
|
|
|
|
|
|
|
import Title from './Title'
|
|
|
|
import Links from './Links'
|
|
|
|
import Desc from './Desc'
|
|
|
|
import Attachments from './Attachments'
|
2017-09-10 21:17:56 +00:00
|
|
|
import Info from './Info'
|
2017-03-07 03:49:46 +00:00
|
|
|
|
|
|
|
class ReactTopicCard extends Component {
|
2017-09-08 20:58:17 +00:00
|
|
|
|
2017-03-07 03:49:46 +00:00
|
|
|
render = () => {
|
2017-03-16 21:58:56 +00:00
|
|
|
const { currentUser, onTopicFollow, updateTopic } = this.props
|
|
|
|
const topic = this.props.openTopic
|
|
|
|
|
|
|
|
if (!topic) return null
|
|
|
|
|
|
|
|
const wrappedUpdateTopic = obj => updateTopic(topic, obj)
|
|
|
|
const wrappedTopicFollow = () => onTopicFollow(topic)
|
|
|
|
|
|
|
|
const authorizedToEdit = topic.authorizeToEdit(currentUser)
|
|
|
|
const isFollowing = topic.isFollowedBy(currentUser)
|
2017-03-07 03:49:46 +00:00
|
|
|
const hasAttachment = topic.get('link') && topic.get('link') !== ''
|
|
|
|
|
|
|
|
let classname = 'permission'
|
|
|
|
if (authorizedToEdit) {
|
|
|
|
classname += ' canEdit'
|
|
|
|
} else {
|
|
|
|
classname += ' cannotEdit'
|
|
|
|
}
|
2017-03-16 21:58:56 +00:00
|
|
|
if (topic.authorizePermissionChange(currentUser)) classname += ' yourTopic'
|
2017-03-07 03:49:46 +00:00
|
|
|
|
|
|
|
return (
|
2017-03-22 16:09:47 +00:00
|
|
|
<Draggable handle=".metacodeImage" defaultPosition={{x: 100, y: 100}}>
|
2017-03-22 23:22:38 +00:00
|
|
|
<div className="showcard mapElement mapElementHidden">
|
2017-03-22 16:09:47 +00:00
|
|
|
<div className={classname}>
|
|
|
|
<div className={`CardOnGraph ${hasAttachment ? 'hasAttachment' : ''}`} id={`topic_${topic.id}`}>
|
|
|
|
<Links topic={topic}
|
2017-09-10 21:17:56 +00:00
|
|
|
onTopicFollow={onTopicFollow}
|
2017-03-22 16:09:47 +00:00
|
|
|
ActiveMapper={this.props.currentUser}
|
|
|
|
updateTopic={wrappedUpdateTopic}
|
|
|
|
metacodeSets={this.props.metacodeSets}
|
|
|
|
redrawCanvas={this.props.redrawCanvas}
|
|
|
|
/>
|
2017-09-08 20:58:17 +00:00
|
|
|
<Title name={topic.get('name')}
|
|
|
|
authorizedToEdit={authorizedToEdit}
|
|
|
|
onChange={wrappedUpdateTopic}
|
|
|
|
/>
|
2017-03-22 16:09:47 +00:00
|
|
|
<Desc desc={topic.get('desc')}
|
|
|
|
authorizedToEdit={authorizedToEdit}
|
|
|
|
onChange={wrappedUpdateTopic}
|
|
|
|
/>
|
|
|
|
<Attachments topic={topic}
|
|
|
|
authorizedToEdit={authorizedToEdit}
|
|
|
|
updateTopic={wrappedUpdateTopic}
|
|
|
|
/>
|
2017-09-10 21:17:56 +00:00
|
|
|
<Info topic={topic} />
|
2017-03-22 16:09:47 +00:00
|
|
|
<div className="clearfloat"></div>
|
|
|
|
</div>
|
2017-03-16 21:58:56 +00:00
|
|
|
</div>
|
2017-03-07 03:49:46 +00:00
|
|
|
</div>
|
2017-03-22 16:09:47 +00:00
|
|
|
</Draggable>
|
2017-03-07 03:49:46 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-08 20:58:17 +00:00
|
|
|
//
|
2017-03-07 03:49:46 +00:00
|
|
|
ReactTopicCard.propTypes = {
|
2017-03-16 21:58:56 +00:00
|
|
|
openTopic: PropTypes.object,
|
|
|
|
currentUser: PropTypes.object,
|
2017-03-07 03:49:46 +00:00
|
|
|
updateTopic: PropTypes.func,
|
2017-03-16 21:58:56 +00:00
|
|
|
onTopicFollow: PropTypes.func,
|
2017-03-07 03:49:46 +00:00
|
|
|
metacodeSets: PropTypes.arrayOf(PropTypes.shape({
|
|
|
|
name: PropTypes.string,
|
|
|
|
metacodes: PropTypes.arrayOf(PropTypes.shape({
|
|
|
|
id: PropTypes.number,
|
|
|
|
icon_path: PropTypes.string, // url
|
|
|
|
name: PropTypes.string
|
|
|
|
}))
|
|
|
|
})),
|
|
|
|
redrawCanvas: PropTypes.func
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ReactTopicCard
|