|
@@ -441,6 +441,7 @@ const displayPokemon = (pkmnName, target) => {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
+// ---- Display Logic ----
|
|
|
const colorSearchResultsTarget = document.getElementById("color-results");
|
|
|
colorSearchResults.subscribe(() => {
|
|
|
colorSearchResultsTarget.innerHTML = "";
|
|
@@ -449,4 +450,31 @@ colorSearchResults.subscribe(() => {
|
|
|
);
|
|
|
});
|
|
|
|
|
|
+// ---- Name Search ----
|
|
|
+U.element("nameSearch", ({ input, button }) => {
|
|
|
+ const nameSearchInput = U.field(input);
|
|
|
+
|
|
|
+ const lookupLimit = 24;
|
|
|
+ const pokemonLookup = new Fuse(pokemonData, { keys: ["name"] });
|
|
|
+ const nameSearchResults = U.obs(() =>
|
|
|
+ pokemonLookup
|
|
|
+ .search(nameSearchInput.value, { limit: lookupLimit })
|
|
|
+ .map(({ item: { name } }) => name)
|
|
|
+ );
|
|
|
+
|
|
|
+ button.addEventListener("click", () => {
|
|
|
+ nameSearchResults.value = Array.from(
|
|
|
+ { length: lookupLimit },
|
|
|
+ () => pokemonData[Math.floor(Math.random() * pokemonData.length)].name
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
+ const nameResultsTarget = document.getElementById("name-results");
|
|
|
+ nameSearchResults.subscribe(() => {
|
|
|
+ nameResultsTarget.innerHTML = "";
|
|
|
+ nameSearchResults.value.forEach((name) => displayPokemon(name, nameResultsTarget));
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+// ---- Initial Target ----
|
|
|
randomizeTargetColor();
|