2016-10-15 21:06:30 +11:00
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2016-10-29 05:26:49 +11:00
|
|
|
import AccountContainer from '../../followers/containers/account_container';
|
2016-10-15 21:06:30 +11:00
|
|
|
|
|
|
|
const outerStyle = {
|
2016-10-17 02:04:13 +11:00
|
|
|
position: 'relative'
|
2016-10-15 21:06:30 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
const headerStyle = {
|
|
|
|
fontSize: '14px',
|
|
|
|
fontWeight: '500',
|
|
|
|
display: 'block',
|
|
|
|
padding: '10px',
|
|
|
|
color: '#9baec8',
|
|
|
|
background: '#454b5e',
|
2016-10-29 05:26:49 +11:00
|
|
|
overflow: 'hidden'
|
2016-10-15 21:06:30 +11:00
|
|
|
};
|
|
|
|
|
2016-10-17 02:04:13 +11:00
|
|
|
const nextStyle = {
|
2016-10-29 05:26:49 +11:00
|
|
|
display: 'inline-block',
|
|
|
|
float: 'right',
|
2016-10-17 02:04:13 +11:00
|
|
|
fontWeight: '400',
|
|
|
|
color: '#2b90d9'
|
|
|
|
};
|
|
|
|
|
2016-10-15 21:06:30 +11:00
|
|
|
const SuggestionsBox = React.createClass({
|
|
|
|
|
|
|
|
propTypes: {
|
2016-10-29 05:26:49 +11:00
|
|
|
accountIds: ImmutablePropTypes.list,
|
2016-10-17 02:04:13 +11:00
|
|
|
perWindow: React.PropTypes.number
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState () {
|
|
|
|
return {
|
|
|
|
index: 0
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps () {
|
|
|
|
return {
|
|
|
|
perWindow: 2
|
|
|
|
};
|
2016-10-15 21:06:30 +11:00
|
|
|
},
|
|
|
|
|
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
|
2016-10-17 02:04:13 +11:00
|
|
|
handleNextClick (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
let newIndex = this.state.index + 1;
|
|
|
|
|
2016-10-29 05:26:49 +11:00
|
|
|
if (this.props.accountIds.skip(this.props.perWindow * newIndex).size === 0) {
|
2016-10-17 02:04:13 +11:00
|
|
|
newIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ index: newIndex });
|
|
|
|
},
|
|
|
|
|
2016-10-15 21:06:30 +11:00
|
|
|
render () {
|
2016-10-29 05:26:49 +11:00
|
|
|
const { accountIds, perWindow } = this.props;
|
2016-10-15 21:06:30 +11:00
|
|
|
|
2016-10-29 05:26:49 +11:00
|
|
|
if (!accountIds || accountIds.size === 0) {
|
2016-10-16 01:54:50 +11:00
|
|
|
return <div />;
|
|
|
|
}
|
|
|
|
|
2016-10-17 02:04:13 +11:00
|
|
|
let nextLink = '';
|
|
|
|
|
2016-10-29 05:26:49 +11:00
|
|
|
if (accountIds.size > perWindow) {
|
|
|
|
nextLink = <a href='#' style={nextStyle} onClick={this.handleNextClick}>Refresh</a>;
|
2016-10-17 02:04:13 +11:00
|
|
|
}
|
|
|
|
|
2016-10-15 21:06:30 +11:00
|
|
|
return (
|
|
|
|
<div style={outerStyle}>
|
2016-10-17 02:04:13 +11:00
|
|
|
<strong style={headerStyle}>
|
|
|
|
Who to follow {nextLink}
|
|
|
|
</strong>
|
2016-10-15 21:06:30 +11:00
|
|
|
|
2016-10-29 05:26:49 +11:00
|
|
|
{accountIds.skip(perWindow * this.state.index).take(perWindow).map(accountId => <AccountContainer key={accountId} id={accountId} withNote={false} />)}
|
2016-10-15 21:06:30 +11:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
export default SuggestionsBox;
|