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';
|
2018-06-03 04:18:03 +00:00
|
|
|
import classnames from 'classnames';
|
2015-12-28 23:34:32 +00:00
|
|
|
import UserListItem from './UserListItem';
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-05 23:46:22 +00:00
|
|
|
listRef = el => {
|
|
|
|
this.list = el;
|
|
|
|
};
|
2017-02-16 21:56:32 +00:00
|
|
|
|
2017-03-30 02:53:54 +00:00
|
|
|
renderUser = ({ index, style, key }) => {
|
2017-05-27 05:30:22 +00:00
|
|
|
const { users, onNickClick } = this.props;
|
2016-02-06 00:54:21 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<UserListItem
|
2017-03-30 02:53:54 +00:00
|
|
|
key={key}
|
2018-04-25 03:36:27 +00:00
|
|
|
user={users[index]}
|
2017-03-23 19:38:27 +00:00
|
|
|
style={style}
|
2017-05-27 05:30:22 +00:00
|
|
|
onClick={onNickClick}
|
2016-02-06 00:54:21 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
render() {
|
2017-05-27 05:30:22 +00:00
|
|
|
const { users, showUserList } = this.props;
|
2018-06-03 04:18:03 +00:00
|
|
|
|
|
|
|
const className = classnames('userlist', {
|
|
|
|
'off-canvas': showUserList
|
|
|
|
});
|
2015-12-28 23:34:32 +00:00
|
|
|
|
|
|
|
return (
|
2017-05-27 05:30:22 +00:00
|
|
|
<div className={className}>
|
2017-03-23 19:38:27 +00:00
|
|
|
<AutoSizer disableWidth>
|
|
|
|
{({ height }) => (
|
|
|
|
<List
|
|
|
|
ref={this.listRef}
|
|
|
|
width={200}
|
|
|
|
height={height - 20}
|
2018-04-25 03:36:27 +00:00
|
|
|
rowCount={users.length}
|
2017-03-23 19:38:27 +00:00
|
|
|
rowHeight={24}
|
|
|
|
rowRenderer={this.renderUser}
|
2017-05-07 20:19:15 +00:00
|
|
|
className="rvlist-users"
|
2017-03-23 19:38:27 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</AutoSizer>
|
2015-12-28 23:34:32 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|