improve topic card readability and fix dragging bug

This commit is contained in:
Connor Turland 2017-03-13 07:36:27 -04:00
parent b09c876ea3
commit ea82a9df27
2 changed files with 37 additions and 34 deletions

View file

@ -10,8 +10,6 @@ import GlobalUI, { ReactApp } from '../GlobalUI'
const TopicCard = { const TopicCard = {
openTopic: null, // stores the topic that's currently open openTopic: null, // stores the topic that's currently open
metacodeSets: [], metacodeSets: [],
updateTopic: () => {},
onTopicFollow: () => {},
redrawCanvas: () => { redrawCanvas: () => {
Visualize.mGraph.plot() Visualize.mGraph.plot()
}, },
@ -19,32 +17,26 @@ const TopicCard = {
const self = TopicCard const self = TopicCard
self.metacodeSets = serverData.metacodeSets self.metacodeSets = serverData.metacodeSets
}, },
populateShowCard: function(topic) { onTopicFollow: topic => {
const self = TopicCard const self = TopicCard
TopicCard.updateTopic = obj => { const isFollowing = topic.isFollowedBy(Active.Mapper)
topic.save(obj, { success: topic => self.populateShowCard(topic) }) $.post({
} url: `/topics/${topic.id}/${isFollowing ? 'un' : ''}follow`
TopicCard.onTopicFollow = () => {
const isFollowing = topic.isFollowedBy(Active.Mapper)
$.post({
url: `/topics/${topic.id}/${isFollowing ? 'un' : ''}follow`
})
if (isFollowing) {
GlobalUI.notifyUser('You are no longer following this topic')
Active.Mapper.unfollowTopic(topic.id)
} else {
GlobalUI.notifyUser('You are now following this topic')
Active.Mapper.followTopic(topic.id)
}
self.populateShowCard(topic)
}
// initialize draggability
$('.showcard').draggable({
handle: '.metacodeImage',
stop: function() {
$(this).height('auto')
}
}) })
if (isFollowing) {
GlobalUI.notifyUser('You are no longer following this topic')
Active.Mapper.unfollowTopic(topic.id)
} else {
GlobalUI.notifyUser('You are now following this topic')
Active.Mapper.followTopic(topic.id)
}
self.render()
},
updateTopic: (topic, obj) => {
const self = TopicCard
topic.save(obj, { success: self.render })
},
render: function() {
ReactApp.render() ReactApp.render()
}, },
showCard: function(node, opts = {}) { showCard: function(node, opts = {}) {
@ -52,8 +44,16 @@ const TopicCard = {
var topic = node.getData('topic') var topic = node.getData('topic')
self.openTopic = topic self.openTopic = topic
// populate the card that's about to show with the right topics data // populate the card that's about to show with the right topics data
self.populateShowCard(topic) self.render()
return $('.showcard').fadeIn('fast', () => opts.complete && opts.complete()) $('.showcard').fadeIn('fast', () => {
$('.showcard').draggable({
handle: '.metacodeImage',
stop: function() {
$(this).height('auto')
}
})
opts.complete && opts.complete()
})
}, },
hideCard: function() { hideCard: function() {
var self = TopicCard var self = TopicCard

View file

@ -9,11 +9,14 @@ import Util from '../../Metamaps/Util'
class ReactTopicCard extends Component { class ReactTopicCard extends Component {
render = () => { render = () => {
const { currentUser, onTopicFollow } = this.props const { currentUser, onTopicFollow, updateTopic } = this.props
const topic = this.props.openTopic const topic = this.props.openTopic
if (!topic) return null if (!topic) return null
const wrappedUpdateTopic = obj => updateTopic(topic, obj)
const wrappedTopicFollow = () => onTopicFollow(topic)
const authorizedToEdit = topic.authorizeToEdit(currentUser) const authorizedToEdit = topic.authorizeToEdit(currentUser)
const isFollowing = topic.isFollowedBy(currentUser) const isFollowing = topic.isFollowedBy(currentUser)
const hasAttachment = topic.get('link') && topic.get('link') !== '' const hasAttachment = topic.get('link') && topic.get('link') !== ''
@ -32,23 +35,23 @@ class ReactTopicCard extends Component {
<div className={`CardOnGraph ${hasAttachment ? 'hasAttachment' : ''}`} id={`topic_${topic.id}`}> <div className={`CardOnGraph ${hasAttachment ? 'hasAttachment' : ''}`} id={`topic_${topic.id}`}>
<Title name={topic.get('name')} <Title name={topic.get('name')}
authorizedToEdit={authorizedToEdit} authorizedToEdit={authorizedToEdit}
onChange={this.props.updateTopic} onChange={wrappedUpdateTopic}
/> />
<Links topic={topic} <Links topic={topic}
ActiveMapper={this.props.currentUser} ActiveMapper={this.props.currentUser}
updateTopic={this.props.updateTopic} updateTopic={wrappedUpdateTopic}
metacodeSets={this.props.metacodeSets} metacodeSets={this.props.metacodeSets}
redrawCanvas={this.props.redrawCanvas} redrawCanvas={this.props.redrawCanvas}
/> />
<Desc desc={topic.get('desc')} <Desc desc={topic.get('desc')}
authorizedToEdit={authorizedToEdit} authorizedToEdit={authorizedToEdit}
onChange={this.props.updateTopic} onChange={wrappedUpdateTopic}
/> />
<Attachments topic={topic} <Attachments topic={topic}
authorizedToEdit={authorizedToEdit} authorizedToEdit={authorizedToEdit}
updateTopic={this.props.updateTopic} updateTopic={wrappedUpdateTopic}
/> />
{Util.isTester(currentUser) && <Follow isFollowing={isFollowing} onTopicFollow={onTopicFollow} />} {Util.isTester(currentUser) && <Follow isFollowing={isFollowing} onTopicFollow={wrappedTopicFollow} />}
<div className="clearfloat"></div> <div className="clearfloat"></div>
</div> </div>
</div> </div>