From 1caa46673d43a4556caed7f2c261e06dc83e1d9c Mon Sep 17 00:00:00 2001 From: FullLifeGames Date: Thu, 3 Oct 2024 15:44:23 +0200 Subject: [PATCH] New: Enable lead search --- src/util/validator.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/util/validator.ts b/src/util/validator.ts index a170a9d..2082144 100644 --- a/src/util/validator.ts +++ b/src/util/validator.ts @@ -12,13 +12,17 @@ export const determineValidTeams = ( for (const rawSearchQuery of rawSearchQueries) { let valid = false; const trimmedSearchQuery = rawSearchQuery.trim().toLowerCase(); - let searchQuery = trimmedSearchQuery; + // People are able to search for leads, e.g. "(Lead) Zapdos" + const lead = trimmedSearchQuery.includes("(lead)"); + let searchQuery = trimmedSearchQuery.replace("(lead)", "").trim(); if (searchQuery.startsWith("-")) { searchQuery = searchQuery.slice(1); } if (team.pokemon) { - valid ||= team.pokemon.some((pokemon) => - pokemon.name?.toLowerCase().includes(searchQuery), + valid ||= team.pokemon.some( + (pokemon) => + pokemon.name?.toLowerCase().includes(searchQuery) && + (!lead || pokemon.lead), ); valid ||= team.pokemon.some((pokemon) => pokemon.moves?.some((move) => move.toLowerCase().includes(searchQuery)), @@ -29,16 +33,20 @@ export const determineValidTeams = ( valid ||= team.pokemon.some((pokemon) => pokemon.item?.toLowerCase().includes(searchQuery), ); - valid ||= team.pokemon.some((pokemon) => - pokemon.altNames?.some((altName) => - altName.toLowerCase().includes(searchQuery), - ), + valid ||= team.pokemon.some( + (pokemon) => + pokemon.altNames?.some((altName) => + altName.toLowerCase().includes(searchQuery), + ) && + (!lead || pokemon.lead), ); valid ||= team.pokemon.some((pokemon) => pokemon.teraType?.toLowerCase().includes(searchQuery), ); - valid ||= team.pokemon.some((pokemon) => - pokemon.formName?.toLowerCase().includes(searchQuery), + valid ||= team.pokemon.some( + (pokemon) => + pokemon.formName?.toLowerCase().includes(searchQuery) && + (!lead || pokemon.lead), ); } if (team.format) {