mirror of https://github.com/vector-im/riot-web
Initial work on improving invite dialog
parent
2b91b0d9c4
commit
b41787c335
|
@ -167,11 +167,21 @@ module.exports = React.createClass({
|
|||
const query = ev.target.value;
|
||||
let queryList = [];
|
||||
|
||||
if (query.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.queryChangedDebouncer) {
|
||||
clearTimeout(this.queryChangedDebouncer);
|
||||
}
|
||||
this.queryChangedDebouncer = setTimeout(() => {
|
||||
// Only do search if there is something to search
|
||||
if (query.length > 0 && query != '@') {
|
||||
// filter the known users list
|
||||
queryList = this._userList.filter((user) => {
|
||||
return this._matches(query, user);
|
||||
}).sort((userA, userB) => {
|
||||
return this._sortedMatches(query, userA, userB);
|
||||
}).map((user) => {
|
||||
// Return objects, structure of which is defined
|
||||
// by InviteAddressType
|
||||
|
@ -201,11 +211,11 @@ module.exports = React.createClass({
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.setState({
|
||||
queryList: queryList,
|
||||
error: false,
|
||||
});
|
||||
}, 200);
|
||||
},
|
||||
|
||||
onDismissed: function(index) {
|
||||
|
@ -349,8 +359,8 @@ module.exports = React.createClass({
|
|||
return false;
|
||||
}
|
||||
|
||||
// direct prefix matches
|
||||
if (name.indexOf(query) === 0 || uid.indexOf(query) === 0) {
|
||||
// positional matches
|
||||
if (name.indexOf(query) !== -1 || uid.indexOf(query) !== -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -374,6 +384,16 @@ module.exports = React.createClass({
|
|||
return false;
|
||||
},
|
||||
|
||||
_sortedMatches: function(query, userA, userB) {
|
||||
if (userA.displayName.startsWith(query) || userA.userId.startsWith(query)) {
|
||||
return -1;
|
||||
}
|
||||
if (userA.displayName.length === query.length) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
|
||||
_isOnInviteList: function(uid) {
|
||||
for (let i = 0; i < this.state.inviteList.length; i++) {
|
||||
if (
|
||||
|
|
Loading…
Reference in New Issue