2015-12-28 23:34:32 +00:00
|
|
|
import React, { Component } from 'react';
|
2016-02-06 00:54:21 +00:00
|
|
|
import { VirtualScroll } from 'react-virtualized';
|
2015-12-28 23:34:32 +00:00
|
|
|
import pure from 'pure-render-decorator';
|
|
|
|
import UserListItem from './UserListItem';
|
|
|
|
|
|
|
|
@pure
|
|
|
|
export default class UserList extends Component {
|
|
|
|
state = {
|
|
|
|
height: window.innerHeight - 100
|
2016-01-06 23:28:11 +00:00
|
|
|
};
|
2015-12-28 23:34:32 +00:00
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
window.addEventListener('resize', this.handleResize);
|
|
|
|
}
|
|
|
|
|
2016-02-16 21:43:25 +00:00
|
|
|
componentWillUpdate(nextProps) {
|
|
|
|
if (nextProps.users.size === this.props.users.size) {
|
|
|
|
this.refs.list.forceUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
window.removeEventListener('resize', this.handleResize);
|
|
|
|
}
|
|
|
|
|
2016-02-06 00:54:21 +00:00
|
|
|
getRowHeight = index => {
|
|
|
|
if (index === 0 || index === this.props.users.size + 1) {
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 24;
|
|
|
|
};
|
|
|
|
|
2016-02-16 21:43:25 +00:00
|
|
|
handleResize = () => this.setState({ height: window.innerHeight - 100 });
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2016-02-06 00:54:21 +00:00
|
|
|
renderUser = index => {
|
|
|
|
const { users } = this.props;
|
|
|
|
|
|
|
|
if (index === 0 || index === users.size + 1) {
|
|
|
|
return <span style={{ height: '10px' }}></span>;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { tab, openPrivateChat, select } = this.props;
|
|
|
|
const user = users.get(index - 1);
|
|
|
|
return (
|
|
|
|
<UserListItem
|
|
|
|
key={user.nick}
|
|
|
|
user={user}
|
|
|
|
tab={tab}
|
|
|
|
openPrivateChat={openPrivateChat}
|
|
|
|
select={select}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
render() {
|
2016-02-06 00:54:21 +00:00
|
|
|
const { tab, showUserList } = this.props;
|
2016-01-11 22:31:06 +00:00
|
|
|
const className = showUserList ? 'userlist off-canvas' : 'userlist';
|
2015-12-28 23:34:32 +00:00
|
|
|
const style = {};
|
|
|
|
|
|
|
|
if (!tab.channel) {
|
|
|
|
style.display = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2016-01-11 22:31:06 +00:00
|
|
|
<div className={className} style={style}>
|
2016-02-06 00:54:21 +00:00
|
|
|
<VirtualScroll
|
2016-02-16 21:43:25 +00:00
|
|
|
ref="list"
|
2016-02-06 00:54:21 +00:00
|
|
|
height={this.state.height}
|
|
|
|
rowsCount={this.props.users.size + 2}
|
|
|
|
rowHeight={this.getRowHeight}
|
|
|
|
rowRenderer={this.renderUser}
|
|
|
|
/>
|
2015-12-28 23:34:32 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|