about summary refs log tree commit diff
path: root/app/assets/javascripts/components/features/compose/components/suggestions_box.jsx
blob: 70c2fca6e0102cdb3d207fb25382aa93b00b9e52 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import PureRenderMixin    from 'react-addons-pure-render-mixin';
import ImmutablePropTypes from 'react-immutable-proptypes';
import AccountContainer   from '../../followers/containers/account_container';

const outerStyle = {
  position: 'relative'
};

const headerStyle = {
  fontSize: '14px',
  fontWeight: '500',
  display: 'block',
  padding: '10px',
  color: '#9baec8',
  background: '#454b5e',
  overflow: 'hidden'
};

const nextStyle = {
  display: 'inline-block',
  float: 'right',
  fontWeight: '400',
  color: '#2b90d9'
};

const SuggestionsBox = React.createClass({

  propTypes: {
    accountIds: ImmutablePropTypes.list,
    perWindow: React.PropTypes.number
  },

  getInitialState () {
    return {
      index: 0
    };
  },

  getDefaultProps () {
    return {
      perWindow: 2
    };
  },

  mixins: [PureRenderMixin],

  handleNextClick (e) {
    e.preventDefault();

    let newIndex = this.state.index + 1;

    if (this.props.accountIds.skip(this.props.perWindow * newIndex).size === 0) {
      newIndex = 0;
    }

    this.setState({ index: newIndex });
  },

  render () {
    const { accountIds, perWindow } = this.props;

    if (!accountIds || accountIds.size === 0) {
      return <div />;
    }

    let nextLink = '';

    if (accountIds.size > perWindow) {
      nextLink = <a href='#' style={nextStyle} onClick={this.handleNextClick}>Refresh</a>;
    }

    return (
      <div style={outerStyle}>
        <strong style={headerStyle}>
          Who to follow {nextLink}
        </strong>

        {accountIds.skip(perWindow * this.state.index).take(perWindow).map(accountId => <AccountContainer key={accountId} id={accountId} withNote={false} />)}
      </div>
    );
  }

});

export default SuggestionsBox;