about summary refs log tree commit diff
path: root/app/assets/javascripts/components/features/account/components/action_bar.jsx
blob: a6eb01d618ed292ad2347354d13a22a9b86224a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import PureRenderMixin    from 'react-addons-pure-render-mixin';
import ImmutablePropTypes from 'react-immutable-proptypes';
import Button             from '../../../components/button';

const ActionBar = React.createClass({

  propTypes: {
    account: ImmutablePropTypes.map.isRequired,
    me: React.PropTypes.number.isRequired,
    onFollow: React.PropTypes.func.isRequired,
    onUnfollow: React.PropTypes.func.isRequired
  },

  mixins: [PureRenderMixin],

  render () {
    const { account, me } = this.props;
    
    let followBack   = '';
    let actionButton = '';

    if (account.get('id') === me) {
      actionButton = 'This is you!';
    } else {
      if (account.getIn(['relationship', 'following'])) {
        actionButton = <Button text='Unfollow' onClick={this.props.onUnfollow} />
      } else {
        actionButton = <Button text='Follow' onClick={this.props.onFollow} />
      }

      if (account.getIn(['relationship', 'followed_by'])) {
        followBack = 'follows you';
      }
    }

    return (
      <div>
        {actionButton}
        {account.get('followers_count')} followers
        {account.get('following_count')} following
        {followBack}
      </div>
    );
  },

});

export default ActionBar;