Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teambuilder: Debounce searching teams #2270

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -3239,11 +3241,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
Loading