Add manifest.json, icons and install button, flatten client/src
This commit is contained in:
parent
a219e689c1
commit
474afda9c2
105 changed files with 338 additions and 283 deletions
92
client/js/components/pages/Chat/UserList.js
Normal file
92
client/js/components/pages/Chat/UserList.js
Normal file
|
@ -0,0 +1,92 @@
|
|||
import React, { PureComponent, createRef } from 'react';
|
||||
import { VariableSizeList as List } from 'react-window';
|
||||
import AutoSizer from 'react-virtualized-auto-sizer';
|
||||
import classnames from 'classnames';
|
||||
import UserListItem from './UserListItem';
|
||||
|
||||
export default class UserList extends PureComponent {
|
||||
list = createRef();
|
||||
|
||||
getSnapshotBeforeUpdate(prevProps) {
|
||||
if (this.list.current) {
|
||||
const { users } = this.props;
|
||||
|
||||
if (prevProps.users.length !== users.length) {
|
||||
this.list.current.resetAfterIndex(
|
||||
Math.min(prevProps.users.length, users.length) + 1
|
||||
);
|
||||
} else {
|
||||
this.list.current.forceUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
getItemHeight = index => {
|
||||
const { users } = this.props;
|
||||
|
||||
if (index === 0) {
|
||||
return 12;
|
||||
} else if (index === users.length + 1) {
|
||||
return 10;
|
||||
}
|
||||
return 24;
|
||||
};
|
||||
|
||||
getItemKey = index => {
|
||||
const { users } = this.props;
|
||||
|
||||
if (index === 0) {
|
||||
return 'top';
|
||||
} else if (index === users.length + 1) {
|
||||
return 'bottom';
|
||||
}
|
||||
return index;
|
||||
};
|
||||
|
||||
renderUser = ({ index, style }) => {
|
||||
const { users, coloredNicks, onNickClick } = this.props;
|
||||
|
||||
if (index === 0 || index === users.length + 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<UserListItem
|
||||
user={users[index - 1]}
|
||||
coloredNick={coloredNicks}
|
||||
style={style}
|
||||
onClick={onNickClick}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { users, showUserList } = this.props;
|
||||
|
||||
const className = classnames('userlist', {
|
||||
'off-canvas': showUserList
|
||||
});
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<AutoSizer disableWidth>
|
||||
{({ height }) => (
|
||||
<List
|
||||
ref={this.list}
|
||||
width={200}
|
||||
height={height}
|
||||
itemCount={users.length + 2}
|
||||
itemKey={this.getItemKey}
|
||||
itemSize={this.getItemHeight}
|
||||
estimatedItemSize={24}
|
||||
>
|
||||
{this.renderUser}
|
||||
</List>
|
||||
)}
|
||||
</AutoSizer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue