I’ve been working on a scouting web app, just wondering if anyone has ever made a search box being able to search teams by their number or nickname with autocomplete. Just like how the search box is on TBA. Because you can only view 500 teams at a time, it takes insanely long to switch pages. Just wondering if theres any way to make it as snappy as the one on tba. Realistically you’ll only ever need to search teams that are bound to your regional event, but I am still wondering. Here’s the code I’ve been using to test it on node.
const fetch = require("node-fetch");
const baseURL = "https://www.thebluealliance.com/api/v3";
const key = "key";
const callAPI = async route => {
return await fetch(baseURL + route, {
method: "GET",
withCredentials: true,
headers: {
"X-TBA-Auth-Key": key
}
});
};
const searchTeams = async (input, page) => {
console.clear();
console.log("page:", page);
let apiResp = await callAPI(`/teams/${page}/simple`);
let data = await apiResp.json();
if (Object.keys(data).length == 0) {
return [];
}
let matches = data
.filter(
team =>
team.key.toLowerCase().includes(input.toLowerCase()) ||
team.nickname.toLowerCase().includes(input.toLowerCase())
)
.map(teamObj => {
let obj = {};
obj["team_number"] = teamObj.team_number;
obj["nickname"] = teamObj.nickname;
return obj;
});
return matches.concat(await searchTeams(input, page + 1));
};
searchTeams("rambot", 0).then(function(result) {
console.log(result);
console.log(result.length, "matches");
});