Skip to content

Commit

Permalink
Teambuilder: Debounce searching teams (smogon#2270)
Browse files Browse the repository at this point in the history
Only debounce for 500+ teams
  • Loading branch information
PartMan7 authored and shrianshChari committed Oct 8, 2024
1 parent 97d584d commit 9e2250b
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions play.pokemonshowdown.com/js/client-teambuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@
curFolder: '',
curFolderKeep: '',
curSearchVal: '',
// Debounce value for searching in the teambuilder
searchTimeout: null,

exportMode: false,
formatResources: {},
Expand Down Expand Up @@ -3243,11 +3245,24 @@
this.chartSet(val, selectNext);
},
searchChange: function (e) {
// 91 for right CMD / 93 for left CMD / 17 for CTL
if (e.keyCode !== 91 && e.keyCode !== 93 && e.keyCode !== 17) {
this.curSearchVal = e.currentTarget.value;
var DEBOUNCE_THRESHOLD_TEAMS = 500;
function updateTeamList() {
// 91 for right CMD / 93 for left CMD / 17 for CTL
if (e.keyCode !== 91 && e.keyCode !== 93 && e.keyCode !== 17) {
this.curSearchVal = searchVal;
}
this.updateTeamList();
}

// If the user has a lot of teams, search is debounced to
// ensure this isn't called too frequently while typing
if (Storage.teams.length > DEBOUNCE_THRESHOLD_TEAMS) {
if (this.searchTimeout) clearTimeout(this.searchTimeout);

var searchVal = e.currentTarget.value;
this.searchTimeout = setTimeout(updateTeamList.bind(this), 400);
} else updateTeamList();

},
chartSetCustom: function (val) {
val = toID(val);
Expand Down

0 comments on commit 9e2250b

Please sign in to comment.