dispatch/client/src/js/components/pages/Chat/UserList.js

57 lines
1.3 KiB
JavaScript
Raw Normal View History

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';
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;
};
renderUser = ({ index, style, key }) => {
const { users, onNickClick } = this.props;
2016-02-06 00:54:21 +00:00
return (
<UserListItem
key={key}
2018-04-25 03:36:27 +00:00
user={users[index]}
2017-03-23 19:38:27 +00:00
style={style}
onClick={onNickClick}
2016-02-06 00:54:21 +00:00
/>
);
};
2015-12-28 23:34:32 +00:00
render() {
const { users, showUserList } = this.props;
const className = classnames('userlist', {
'off-canvas': showUserList
});
2015-12-28 23:34:32 +00:00
return (
<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}
className="rvlist-users"
2017-03-23 19:38:27 +00:00
/>
)}
</AutoSizer>
2015-12-28 23:34:32 +00:00
</div>
);
}
}