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

61 lines
1.5 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';
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
}
}
listRef = el => { this.list = el; };
2017-03-23 19:38:27 +00:00
renderUser = ({ index, style }) => {
const { users, tab, openPrivateChat, select } = this.props;
const user = users.get(index);
2016-02-06 00:54:21 +00:00
return (
<UserListItem
key={user.nick}
user={user}
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 = {};
if (!tab.channel) {
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>
);
}
}