You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.7 KiB

  1. import PureRenderMixin from 'react-addons-pure-render-mixin';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import AccountContainer from '../../followers/containers/account_container';
  4. const outerStyle = {
  5. position: 'relative'
  6. };
  7. const headerStyle = {
  8. fontSize: '14px',
  9. fontWeight: '500',
  10. display: 'block',
  11. padding: '10px',
  12. color: '#9baec8',
  13. background: '#454b5e',
  14. overflow: 'hidden'
  15. };
  16. const nextStyle = {
  17. display: 'inline-block',
  18. float: 'right',
  19. fontWeight: '400',
  20. color: '#2b90d9'
  21. };
  22. const SuggestionsBox = React.createClass({
  23. propTypes: {
  24. accountIds: ImmutablePropTypes.list,
  25. perWindow: React.PropTypes.number
  26. },
  27. getInitialState () {
  28. return {
  29. index: 0
  30. };
  31. },
  32. getDefaultProps () {
  33. return {
  34. perWindow: 2
  35. };
  36. },
  37. mixins: [PureRenderMixin],
  38. handleNextClick (e) {
  39. e.preventDefault();
  40. let newIndex = this.state.index + 1;
  41. if (this.props.accountIds.skip(this.props.perWindow * newIndex).size === 0) {
  42. newIndex = 0;
  43. }
  44. this.setState({ index: newIndex });
  45. },
  46. render () {
  47. const { accountIds, perWindow } = this.props;
  48. if (!accountIds || accountIds.size === 0) {
  49. return <div />;
  50. }
  51. let nextLink = '';
  52. if (accountIds.size > perWindow) {
  53. nextLink = <a href='#' style={nextStyle} onClick={this.handleNextClick}>Refresh</a>;
  54. }
  55. return (
  56. <div style={outerStyle}>
  57. <strong style={headerStyle}>
  58. Who to follow {nextLink}
  59. </strong>
  60. {accountIds.skip(perWindow * this.state.index).take(perWindow).map(accountId => <AccountContainer key={accountId} id={accountId} withNote={false} />)}
  61. </div>
  62. );
  63. }
  64. });
  65. export default SuggestionsBox;