Vulcan/packages/_nova-subscribe-to-posts/lib/components/SubscribeButton.jsx

41 lines
1.1 KiB
React
Raw Normal View History

2016-07-27 18:00:40 +02:00
import React, { PropTypes, Component } from 'react';
2016-07-28 21:19:10 +02:00
import { intlShape } from 'react-intl';
import Subscribe from './Subscribe.jsx';
2016-07-27 18:00:40 +02:00
2016-07-28 21:19:10 +02:00
class SubscribeButton extends Subscribe {
2016-07-27 18:00:40 +02:00
render() {
const post = this.props.post;
const user = this.context.currentUser;
// can't subscribe to own post (also validated on server side)
if(user && post.author === user.username) {
2016-07-28 21:19:10 +02:00
return null;
2016-07-27 18:00:40 +02:00
}
let btnStyle = "default";
2016-07-28 21:19:10 +02:00
let btnTitle = "posts.subscribe";
let btnIcon = "eye";
2016-07-27 18:00:40 +02:00
let isSubscribed = this.isSubscribed(post, user);
if( isSubscribed ) {
btnStyle = "info";
2016-07-28 21:19:10 +02:00
btnTitle = "posts.unsubscribe";
btnIcon = "eye-slash";
2016-07-27 18:00:40 +02:00
}
return (
2016-07-28 21:19:10 +02:00
<button type="button" title={this.context.intl.formatMessage({id: btnTitle})}
className={`btn btn-${btnStyle} btn-sm`}
2016-07-27 18:00:40 +02:00
style={{padding: '.5rem', lineHeight: 1, borderRadius: '50%', marginLeft: '.5rem'}}
onClick={this.onSubscribe} >
2016-07-28 21:19:10 +02:00
<i className={`fa fa-${btnIcon}`}></i>
2016-07-27 18:00:40 +02:00
</button>
)
}
}
module.exports = SubscribeButton;
export default SubscribeButton;