Wait a bit before sending filter requests

avoid hammering the server with requests for each keystroke
This commit is contained in:
David Baker 2016-09-16 18:53:18 +01:00
parent 6d332256b5
commit 2fdec51a5b

View File

@ -66,6 +66,7 @@ module.exports = React.createClass({
} }
this.nextBatch = null; this.nextBatch = null;
this.filterString = null; this.filterString = null;
this.filterTimeout = null;
// dis.dispatch({ // dis.dispatch({
// action: 'ui_opacity', // action: 'ui_opacity',
@ -209,7 +210,18 @@ module.exports = React.createClass({
this.showRoomAlias(alias); this.showRoomAlias(alias);
} else { } else {
this.filterString = alias || null; this.filterString = alias || null;
this.refreshRoomList();
// don't send the request for a little bit,
// no point hammering the server with a
// request for every keystroke, let the
// user finish typing.
if (this.filterTimeout) {
clearTimeout(this.filterTimeout);
}
this.filterTimeout = setTimeout(() => {
this.filterTimeout = null;
this.refreshRoomList();
}, 300);
} }
}, },