The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

87 lines
1.9 KiB

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