2017-02-17 00:46:39 +00:00
|
|
|
import React, { PureComponent } from 'react';
|
2017-03-23 19:38:27 +00:00
|
|
|
import { List } from 'react-virtualized/dist/commonjs/List';
|
|
|
|
import { AutoSizer } from 'react-virtualized/dist/commonjs/AutoSizer';
|
2015-12-28 23:34:32 +00:00
|
|
|
import UserListItem from './UserListItem';
|
|
|
|
|
2017-03-23 19:38:27 +00:00
|
|
|
const listStyle = { padding: '10px 0', boxSizing: 'content-box' };
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2017-03-23 19:38:27 +00:00
|
|
|
export default class UserList extends PureComponent {
|
2016-02-16 21:43:25 +00:00
|
|
|
componentWillUpdate(nextProps) {
|
|
|
|
if (nextProps.users.size === this.props.users.size) {
|
2017-03-30 02:12:30 +00:00
|
|
|
this.list.forceUpdateGrid();
|
2016-02-16 21:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-16 21:56:32 +00:00
|
|
|
listRef = el => { this.list = el; };
|
|
|
|
|
2017-03-30 02:53:54 +00:00
|
|
|
renderUser = ({ index, style, key }) => {
|
2017-03-23 19:38:27 +00:00
|
|
|
const { users, tab, openPrivateChat, select } = this.props;
|
2016-02-06 00:54:21 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<UserListItem
|
2017-03-30 02:53:54 +00:00
|
|
|
key={key}
|
|
|
|
user={users.get(index)}
|
2016-02-06 00:54:21 +00:00
|
|
|
tab={tab}
|
|
|
|
openPrivateChat={openPrivateChat}
|
|
|
|
select={select}
|
2017-03-23 19:38:27 +00:00
|
|
|
style={style}
|
2016-02-06 00:54:21 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
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 = {};
|
|
|
|
|
2017-04-19 23:51:55 +00:00
|
|
|
if (!tab.isChannel()) {
|
2015-12-28 23:34:32 +00:00
|
|
|
style.display = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2016-01-11 22:31:06 +00:00
|
|
|
<div className={className} style={style}>
|
2017-03-23 19:38:27 +00:00
|
|
|
<AutoSizer disableWidth>
|
|
|
|
{({ height }) => (
|
|
|
|
<List
|
|
|
|
ref={this.listRef}
|
|
|
|
width={200}
|
|
|
|
height={height - 20}
|
|
|
|
rowCount={this.props.users.size}
|
|
|
|
rowHeight={24}
|
|
|
|
rowRenderer={this.renderUser}
|
|
|
|
style={listStyle}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</AutoSizer>
|
2015-12-28 23:34:32 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|