feat: autocomplete size limits

This commit is contained in:
TrèsAbhi committed 2023-11-01 11:45:19 -05:00
1 parent 882e61ff44
commit 3ea77f5899
5 files changed
+88 -45

No files matched your search

+19 -17
View File
@@ -9,43 +9,45 @@ export type ClanListWithRegion = (Clan & {
export default async function searchClansAcrossRegions(
search: string,
limit = 9,
limit = 25,
) {
const trimmed = search.trim();
if (trimmed.length < 3 && trimmed.length > 100) return [];
const normalizedLimit = Math.round(limit / 3);
const normalizedLimit = Math.floor(limit / 3);
// TODO: remove splice once wargaming fixes the functionality of the limit felid
return (
await Promise.all([
fetchBlitz<ClanList>(
`https://api.wotblitz.com/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`,
).then(
(value) =>
value &&
value.map((account) => ({
).then((value) =>
value
.map((account) => ({
...account,
region: 'com' as Region,
})),
}))
.splice(0, normalizedLimit),
),
fetchBlitz<ClanList>(
`https://api.wotblitz.eu/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`,
).then(
(value) =>
value &&
value.map((account) => ({
).then((value) =>
value
.map((account) => ({
...account,
region: 'eu' as Region,
})),
}))
.splice(0, normalizedLimit),
),
fetchBlitz<ClanList>(
`https://api.wotblitz.asia/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`,
).then(
(value) =>
value &&
value.map((account) => ({
).then((value) =>
value
.map((account) => ({
...account,
region: 'asia' as Region,
})),
}))
.splice(0, normalizedLimit),
),
])
)
+2 -2
View File
@@ -16,10 +16,10 @@ export const usernamePatternWithoutPosition = /[a-zA-Z0-9_]{3,24}/;
export default async function searchPlayersAcrossRegions(
search: string,
limit = 9,
limit = 25,
) {
const trimmedSearch = search.trim();
const normalizedLimit = Math.round(limit / 3);
const normalizedLimit = Math.floor(limit / 3);
const encodedSearch = encodeURIComponent(trimmedSearch);
if (usernamePattern.test(trimmedSearch)) {