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.

122 lines
2.6 KiB

7 years ago
  1. import PureRenderMixin from 'react-addons-pure-render-mixin';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import Avatar from '../../../components/avatar';
  4. import { Link } from 'react-router';
  5. const outerStyle = {
  6. marginBottom: '10px',
  7. borderTop: '1px solid #616b86',
  8. position: 'relative'
  9. };
  10. const headerStyle = {
  11. fontSize: '14px',
  12. fontWeight: '500',
  13. display: 'block',
  14. padding: '10px',
  15. color: '#9baec8',
  16. background: '#454b5e',
  17. width: '120px',
  18. marginTop: '-18px'
  19. };
  20. const itemStyle = {
  21. display: 'block',
  22. padding: '10px',
  23. color: '#9baec8',
  24. overflow: 'hidden',
  25. textDecoration: 'none'
  26. };
  27. const displayNameStyle = {
  28. display: 'block',
  29. fontWeight: '500',
  30. overflow: 'hidden',
  31. textOverflow: 'ellipsis'
  32. };
  33. const acctStyle = {
  34. display: 'block',
  35. overflow: 'hidden',
  36. textOverflow: 'ellipsis'
  37. };
  38. const nextStyle = {
  39. fontWeight: '400',
  40. color: '#2b90d9'
  41. };
  42. const SuggestionsBox = React.createClass({
  43. propTypes: {
  44. accounts: ImmutablePropTypes.list.isRequired,
  45. perWindow: React.PropTypes.number
  46. },
  47. getInitialState () {
  48. return {
  49. index: 0
  50. };
  51. },
  52. getDefaultProps () {
  53. return {
  54. perWindow: 2
  55. };
  56. },
  57. mixins: [PureRenderMixin],
  58. handleNextClick (e) {
  59. e.preventDefault();
  60. let newIndex = this.state.index + 1;
  61. if (this.props.accounts.skip(this.props.perWindow * newIndex).size === 0) {
  62. newIndex = 0;
  63. }
  64. this.setState({ index: newIndex });
  65. },
  66. render () {
  67. const { accounts, perWindow } = this.props;
  68. if (accounts.size === 0) {
  69. return <div />;
  70. }
  71. let nextLink = '';
  72. if (accounts.size > perWindow) {
  73. nextLink = <a href='#' style={nextStyle} onClick={this.handleNextClick}>Next</a>;
  74. }
  75. return (
  76. <div style={outerStyle}>
  77. <strong style={headerStyle}>
  78. Who to follow {nextLink}
  79. </strong>
  80. {accounts.skip(perWindow * this.state.index).take(perWindow).map(account => {
  81. let displayName = account.get('display_name');
  82. if (displayName.length === 0) {
  83. displayName = account.get('username');
  84. }
  85. return (
  86. <Link key={account.get('id')} style={itemStyle} to={`/accounts/${account.get('id')}`}>
  87. <div style={{ float: 'left', marginRight: '10px' }}><Avatar src={account.get('avatar')} size={36} /></div>
  88. <strong style={displayNameStyle}>{displayName}</strong>
  89. <span style={acctStyle}>@{account.get('acct')}</span>
  90. </Link>
  91. )
  92. })}
  93. </div>
  94. );
  95. }
  96. });
  97. export default SuggestionsBox;