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.

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