Expand the list when the overflow element is clicked

Negative truncateAt values means "do not truncate".
This commit is contained in:
Kegan Dougal 2016-01-21 15:57:59 +00:00
parent eed83f982e
commit d72ab641d0
3 changed files with 24 additions and 21 deletions

View file

@ -19,7 +19,7 @@ module.exports = React.createClass({
displayName: 'TruncatedList', displayName: 'TruncatedList',
propTypes: { propTypes: {
// The number of elements to show before truncating // The number of elements to show before truncating. If negative, no truncation is done.
truncateAt: React.PropTypes.number, truncateAt: React.PropTypes.number,
// The className to apply to the wrapping div // The className to apply to the wrapping div
className: React.PropTypes.string, className: React.PropTypes.string,
@ -43,6 +43,8 @@ module.exports = React.createClass({
var childsJsx = this.props.children; var childsJsx = this.props.children;
var overflowJsx; var overflowJsx;
var childCount = React.Children.count(this.props.children); var childCount = React.Children.count(this.props.children);
if (this.props.truncateAt >= 0) {
var overflowCount = childCount - this.props.truncateAt; var overflowCount = childCount - this.props.truncateAt;
if (overflowCount > 0) { if (overflowCount > 0) {
@ -54,6 +56,7 @@ module.exports = React.createClass({
childArray.splice(childCount - overflowCount, overflowCount); childArray.splice(childCount - overflowCount, overflowCount);
childsJsx = childArray; // use what is left childsJsx = childArray; // use what is left
} }
}
return ( return (
<div className={this.props.className}> <div className={this.props.className}>

View file

@ -45,7 +45,7 @@ module.exports = React.createClass({
getDefaultProps: function() { getDefaultProps: function() {
return { return {
shouldComponentUpdate: function(nextProps, nextState) { return false; }, shouldComponentUpdate: function(nextProps, nextState) { return true; },
onClick: function() {}, onClick: function() {},
presenceState: "offline", presenceState: "offline",
presenceActiveAgo: -1, presenceActiveAgo: -1,

View file

@ -42,7 +42,8 @@ module.exports = React.createClass({
var members = this.roomMembers(INITIAL_LOAD_NUM_MEMBERS); var members = this.roomMembers(INITIAL_LOAD_NUM_MEMBERS);
return { return {
members: members members: members,
truncateAt: 3
}; };
}, },
@ -75,9 +76,6 @@ module.exports = React.createClass({
self._loadUserList(); self._loadUserList();
}, 50); }, 50);
setTimeout
// Attach a SINGLE listener for global presence changes then locate the // Attach a SINGLE listener for global presence changes then locate the
// member tile and re-render it. This is more efficient than every tile // member tile and re-render it. This is more efficient than every tile
// evar attaching their own listener. // evar attaching their own listener.
@ -264,16 +262,19 @@ module.exports = React.createClass({
// For now we'll pretend this is any entity. It should probably be a separate tile. // For now we'll pretend this is any entity. It should probably be a separate tile.
var EntityTile = sdk.getComponent("rooms.EntityTile"); var EntityTile = sdk.getComponent("rooms.EntityTile");
var BaseAvatar = sdk.getComponent('avatars.BaseAvatar'); var BaseAvatar = sdk.getComponent('avatars.BaseAvatar');
var text = "and " + overflowCount + " more";
return ( return (
<EntityTile avatarJsx={ <EntityTile avatarJsx={
<BaseAvatar name="+" width={36} height={36} /> <BaseAvatar name="+" width={36} height={36} />
} key="overflow" name={`and ${overflowCount} more`} presenceState="online" } name={text} presenceState="online" suppressOnHover={true}
suppressOnHover={true} onClick={this._showFullMemberList} /> onClick={this._showFullMemberList} />
); );
}, },
_showFullMemberList: function() { _showFullMemberList: function() {
console.log("TODO"); this.setState({
truncateAt: -1
});
}, },
memberSort: function(userIdA, userIdB) { memberSort: function(userIdA, userIdB) {
@ -341,8 +342,7 @@ module.exports = React.createClass({
return; return;
} }
memberList.push( memberList.push(
<EntityTile key={e.getStateKey()} ref={e.getStateKey()} <EntityTile key={e.getStateKey()} name={e.getContent().display_name} />
name={e.getContent().display_name} />
) )
}) })
} }
@ -387,7 +387,7 @@ module.exports = React.createClass({
<div className="mx_MemberList"> <div className="mx_MemberList">
{this.inviteTile()} {this.inviteTile()}
<GeminiScrollbar autoshow={true} className="mx_MemberList_joined mx_MemberList_outerWrapper"> <GeminiScrollbar autoshow={true} className="mx_MemberList_joined mx_MemberList_outerWrapper">
<TruncatedList className="mx_MemberList_wrapper" <TruncatedList className="mx_MemberList_wrapper" truncateAt={this.state.truncateAt}
createOverflowElement={this._createOverflowTile}> createOverflowElement={this._createOverflowTile}>
{this.makeMemberTiles('join', this.state.searchQuery)} {this.makeMemberTiles('join', this.state.searchQuery)}
</TruncatedList> </TruncatedList>