Make suggestions box also use user list components
This commit is contained in:
parent
ac4f53a3a2
commit
bfb6cc5f2c
|
@ -1,11 +1,8 @@
|
||||||
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import Avatar from '../../../components/avatar';
|
import AccountContainer from '../../followers/containers/account_container';
|
||||||
import { Link } from 'react-router';
|
|
||||||
|
|
||||||
const outerStyle = {
|
const outerStyle = {
|
||||||
marginBottom: '10px',
|
|
||||||
borderTop: '1px solid #616b86',
|
|
||||||
position: 'relative'
|
position: 'relative'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,32 +13,12 @@ const headerStyle = {
|
||||||
padding: '10px',
|
padding: '10px',
|
||||||
color: '#9baec8',
|
color: '#9baec8',
|
||||||
background: '#454b5e',
|
background: '#454b5e',
|
||||||
width: '120px',
|
overflow: 'hidden'
|
||||||
marginTop: '-18px'
|
|
||||||
};
|
|
||||||
|
|
||||||
const itemStyle = {
|
|
||||||
display: 'block',
|
|
||||||
padding: '10px',
|
|
||||||
color: '#9baec8',
|
|
||||||
overflow: 'hidden',
|
|
||||||
textDecoration: 'none'
|
|
||||||
};
|
|
||||||
|
|
||||||
const displayNameStyle = {
|
|
||||||
display: 'block',
|
|
||||||
fontWeight: '500',
|
|
||||||
overflow: 'hidden',
|
|
||||||
textOverflow: 'ellipsis'
|
|
||||||
};
|
|
||||||
|
|
||||||
const acctStyle = {
|
|
||||||
display: 'block',
|
|
||||||
overflow: 'hidden',
|
|
||||||
textOverflow: 'ellipsis'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const nextStyle = {
|
const nextStyle = {
|
||||||
|
display: 'inline-block',
|
||||||
|
float: 'right',
|
||||||
fontWeight: '400',
|
fontWeight: '400',
|
||||||
color: '#2b90d9'
|
color: '#2b90d9'
|
||||||
};
|
};
|
||||||
|
@ -49,7 +26,7 @@ const nextStyle = {
|
||||||
const SuggestionsBox = React.createClass({
|
const SuggestionsBox = React.createClass({
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
accounts: ImmutablePropTypes.list.isRequired,
|
accountIds: ImmutablePropTypes.list,
|
||||||
perWindow: React.PropTypes.number
|
perWindow: React.PropTypes.number
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -72,7 +49,7 @@ const SuggestionsBox = React.createClass({
|
||||||
|
|
||||||
let newIndex = this.state.index + 1;
|
let newIndex = this.state.index + 1;
|
||||||
|
|
||||||
if (this.props.accounts.skip(this.props.perWindow * newIndex).size === 0) {
|
if (this.props.accountIds.skip(this.props.perWindow * newIndex).size === 0) {
|
||||||
newIndex = 0;
|
newIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,16 +57,16 @@ const SuggestionsBox = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { accounts, perWindow } = this.props;
|
const { accountIds, perWindow } = this.props;
|
||||||
|
|
||||||
if (accounts.size === 0) {
|
if (!accountIds || accountIds.size === 0) {
|
||||||
return <div />;
|
return <div />;
|
||||||
}
|
}
|
||||||
|
|
||||||
let nextLink = '';
|
let nextLink = '';
|
||||||
|
|
||||||
if (accounts.size > perWindow) {
|
if (accountIds.size > perWindow) {
|
||||||
nextLink = <a href='#' style={nextStyle} onClick={this.handleNextClick}>Next</a>;
|
nextLink = <a href='#' style={nextStyle} onClick={this.handleNextClick}>Refresh</a>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -98,21 +75,7 @@ const SuggestionsBox = React.createClass({
|
||||||
Who to follow {nextLink}
|
Who to follow {nextLink}
|
||||||
</strong>
|
</strong>
|
||||||
|
|
||||||
{accounts.skip(perWindow * this.state.index).take(perWindow).map(account => {
|
{accountIds.skip(perWindow * this.state.index).take(perWindow).map(accountId => <AccountContainer key={accountId} id={accountId} withNote={false} />)}
|
||||||
let displayName = account.get('display_name');
|
|
||||||
|
|
||||||
if (displayName.length === 0) {
|
|
||||||
displayName = account.get('username');
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Link key={account.get('id')} style={itemStyle} to={`/accounts/${account.get('id')}`}>
|
|
||||||
<div style={{ float: 'left', marginRight: '10px' }}><Avatar src={account.get('avatar')} size={36} /></div>
|
|
||||||
<strong style={displayNameStyle}>{displayName}</strong>
|
|
||||||
<span style={acctStyle}>@{account.get('acct')}</span>
|
|
||||||
</Link>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { getSuggestions } from '../../../selectors';
|
|
||||||
import SuggestionsBox from '../components/suggestions_box';
|
import SuggestionsBox from '../components/suggestions_box';
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state) => ({
|
||||||
accounts: getSuggestions(state)
|
accountIds: state.get('suggestions')
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps)(SuggestionsBox);
|
export default connect(mapStateToProps)(SuggestionsBox);
|
||||||
|
|
|
@ -38,6 +38,12 @@ const Account = React.createClass({
|
||||||
withNote: React.PropTypes.bool
|
withNote: React.PropTypes.bool
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getDefaultProps () {
|
||||||
|
return {
|
||||||
|
withNote: true
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
mixins: [PureRenderMixin],
|
mixins: [PureRenderMixin],
|
||||||
|
|
||||||
handleFollow () {
|
handleFollow () {
|
||||||
|
@ -45,7 +51,7 @@ const Account = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { account, me } = this.props;
|
const { account, me, withNote } = this.props;
|
||||||
|
|
||||||
if (!account) {
|
if (!account) {
|
||||||
return <div />;
|
return <div />;
|
||||||
|
@ -53,7 +59,7 @@ const Account = React.createClass({
|
||||||
|
|
||||||
let note, buttons;
|
let note, buttons;
|
||||||
|
|
||||||
if (account.get('note').length > 0) {
|
if (account.get('note').length > 0 && withNote) {
|
||||||
note = <div style={noteStyle}>{account.get('note')}</div>;
|
note = <div style={noteStyle}>{account.get('note')}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,9 +66,3 @@ export const getNotifications = createSelector([getNotificationsBase], (base) =>
|
||||||
|
|
||||||
return arr;
|
return arr;
|
||||||
});
|
});
|
||||||
|
|
||||||
const getSuggestionsBase = (state) => state.get('suggestions');
|
|
||||||
|
|
||||||
export const getSuggestions = createSelector([getSuggestionsBase, getAccounts], (base, accounts) => {
|
|
||||||
return base.map(accountId => accounts.get(accountId));
|
|
||||||
});
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ END
|
||||||
|
|
||||||
query = <<END
|
query = <<END
|
||||||
MATCH (b)
|
MATCH (b)
|
||||||
|
WHERE b.account_id <> {id}
|
||||||
RETURN b.account_id
|
RETURN b.account_id
|
||||||
ORDER BY b.nodeRank DESC
|
ORDER BY b.nodeRank DESC
|
||||||
LIMIT {limit}
|
LIMIT {limit}
|
||||||
|
|
Loading…
Reference in a new issue