Filter the membership list in addition to the search area for the input text
This commit is contained in:
parent
a8643ff039
commit
d2708cf4d4
2 changed files with 42 additions and 13 deletions
|
@ -264,13 +264,23 @@ module.exports = React.createClass({
|
||||||
return latB - latA;
|
return latB - latA;
|
||||||
},
|
},
|
||||||
|
|
||||||
makeMemberTiles: function(membership) {
|
onSearchQueryChanged: function(input) {
|
||||||
|
this.setState({
|
||||||
|
searchQuery: input
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
makeMemberTiles: function(membership, query) {
|
||||||
var MemberTile = sdk.getComponent("rooms.MemberTile");
|
var MemberTile = sdk.getComponent("rooms.MemberTile");
|
||||||
|
query = (query || "").toLowerCase();
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var memberList = self.state.members.filter(function(userId) {
|
var memberList = self.state.members.filter(function(userId) {
|
||||||
var m = self.memberDict[userId];
|
var m = self.memberDict[userId];
|
||||||
|
if (query && m.name.toLowerCase().indexOf(query) !== 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return m.membership == membership;
|
return m.membership == membership;
|
||||||
}).map(function(userId) {
|
}).map(function(userId) {
|
||||||
var m = self.memberDict[userId];
|
var m = self.memberDict[userId];
|
||||||
|
@ -329,20 +339,15 @@ module.exports = React.createClass({
|
||||||
return (
|
return (
|
||||||
<SearchableEntityList searchPlaceholderText={"Invite / Search"}
|
<SearchableEntityList searchPlaceholderText={"Invite / Search"}
|
||||||
onSubmit={this.onInvite}
|
onSubmit={this.onInvite}
|
||||||
entities={
|
onQueryChanged={this.onSearchQueryChanged}
|
||||||
Entities.fromRoomMembers(
|
entities={Entities.fromUsers(allUsers, true, this.onInvite)} />
|
||||||
room.getJoinedMembers()
|
|
||||||
).concat(
|
|
||||||
Entities.fromUsers(allUsers, true, this.onInvite)
|
|
||||||
)
|
|
||||||
} />
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
var invitedSection = null;
|
var invitedSection = null;
|
||||||
var invitedMemberTiles = this.makeMemberTiles('invite');
|
var invitedMemberTiles = this.makeMemberTiles('invite', this.state.searchQuery);
|
||||||
if (invitedMemberTiles.length > 0) {
|
if (invitedMemberTiles.length > 0) {
|
||||||
invitedSection = (
|
invitedSection = (
|
||||||
<div className="mx_MemberList_invited">
|
<div className="mx_MemberList_invited">
|
||||||
|
@ -359,7 +364,7 @@ module.exports = React.createClass({
|
||||||
{this.inviteTile()}
|
{this.inviteTile()}
|
||||||
<div>
|
<div>
|
||||||
<div className="mx_MemberList_wrapper">
|
<div className="mx_MemberList_wrapper">
|
||||||
{this.makeMemberTiles('join')}
|
{this.makeMemberTiles('join', this.state.searchQuery)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{invitedSection}
|
{invitedSection}
|
||||||
|
|
|
@ -26,16 +26,20 @@ var SearchableEntityList = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
searchPlaceholderText: React.PropTypes.string,
|
searchPlaceholderText: React.PropTypes.string,
|
||||||
emptyQueryShowsAll: React.PropTypes.bool,
|
emptyQueryShowsAll: React.PropTypes.bool,
|
||||||
|
showInputBox: React.PropTypes.bool,
|
||||||
|
onQueryChanged: React.PropTypes.func, // fn(inputText)
|
||||||
onSubmit: React.PropTypes.func, // fn(inputText)
|
onSubmit: React.PropTypes.func, // fn(inputText)
|
||||||
entities: React.PropTypes.array
|
entities: React.PropTypes.array
|
||||||
},
|
},
|
||||||
|
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
return {
|
return {
|
||||||
|
showInputBox: true,
|
||||||
searchPlaceholderText: "Search",
|
searchPlaceholderText: "Search",
|
||||||
entities: [],
|
entities: [],
|
||||||
emptyQueryShowsAll: false,
|
emptyQueryShowsAll: false,
|
||||||
onSubmit: function() {}
|
onSubmit: function() {},
|
||||||
|
onQueryChanged: function(input) {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -46,12 +50,24 @@ var SearchableEntityList = React.createClass({
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public-facing method to set the input query text to the given input.
|
||||||
|
* @param {string} input
|
||||||
|
*/
|
||||||
|
setQuery: function(input) {
|
||||||
|
this.setState({
|
||||||
|
query: input,
|
||||||
|
results: this.getSearchResults(input)
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
onQueryChanged: function(ev) {
|
onQueryChanged: function(ev) {
|
||||||
var q = ev.target.value;
|
var q = ev.target.value;
|
||||||
this.setState({
|
this.setState({
|
||||||
query: q,
|
query: q,
|
||||||
results: this.getSearchResults(q)
|
results: this.getSearchResults(q)
|
||||||
});
|
});
|
||||||
|
this.props.onQueryChanged(q);
|
||||||
},
|
},
|
||||||
|
|
||||||
onQuerySubmit: function(ev) {
|
onQuerySubmit: function(ev) {
|
||||||
|
@ -69,13 +85,21 @@ var SearchableEntityList = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
return (
|
var inputBox;
|
||||||
<div>
|
|
||||||
|
if (this.props.showInputBox) {
|
||||||
|
inputBox = (
|
||||||
<form onSubmit={this.onQuerySubmit}>
|
<form onSubmit={this.onQuerySubmit}>
|
||||||
<input className="mx_SearchableEntityList_query" type="text"
|
<input className="mx_SearchableEntityList_query" type="text"
|
||||||
onChange={this.onQueryChanged} value={this.state.query}
|
onChange={this.onQueryChanged} value={this.state.query}
|
||||||
placeholder={this.props.searchPlaceholderText} />
|
placeholder={this.props.searchPlaceholderText} />
|
||||||
</form>
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{inputBox}
|
||||||
<div className="mx_SearchableEntityList_list">
|
<div className="mx_SearchableEntityList_list">
|
||||||
{this.state.results.map((entity) => {
|
{this.state.results.map((entity) => {
|
||||||
return entity.getJsx();
|
return entity.getJsx();
|
||||||
|
|
Loading…
Reference in a new issue