|
@@ -47,6 +47,9 @@ const selectors = {
|
|
|
get colorSearchResults() {
|
|
|
return document.getElementById("color-results");
|
|
|
},
|
|
|
+ get nameSearchResults() {
|
|
|
+ return document.getElementById("name-results");
|
|
|
+ },
|
|
|
set background(hex) {
|
|
|
document.querySelector(":root").style.setProperty("--background", hex);
|
|
|
},
|
|
@@ -315,11 +318,34 @@ const makePokemonTile = (name) => {
|
|
|
return clone;
|
|
|
};
|
|
|
|
|
|
+const pokemonLookup = new Fuse(pokemonData, { keys: ["name"] });
|
|
|
+let currentNameSearchResults = [];
|
|
|
+
|
|
|
+const searchByName = (newSearch) => {
|
|
|
+ currentNameSearchResults = pokemonLookup
|
|
|
+ .search(newSearch, { limit: 10 })
|
|
|
+ .map(({ item: { name } }) => name);
|
|
|
+ showResults();
|
|
|
+};
|
|
|
+
|
|
|
+const randomPokemon = () => {
|
|
|
+ currentNameSearchResults = Array.from(
|
|
|
+ { length: 10 },
|
|
|
+ () => pokemonData[Math.floor(Math.random() * pokemonData.length)].name
|
|
|
+ );
|
|
|
+ showResults();
|
|
|
+};
|
|
|
+
|
|
|
const showResults = () => {
|
|
|
selectors.colorSearchResults.innerHTML = "";
|
|
|
sortedData.slice(0, selectors.resultsToDisplay).forEach((name) => {
|
|
|
selectors.colorSearchResults.appendChild(makePokemonTile(name));
|
|
|
});
|
|
|
+
|
|
|
+ selectors.nameSearchResults.innerHTML = "";
|
|
|
+ currentNameSearchResults.forEach((name) => {
|
|
|
+ selectors.nameSearchResults.appendChild(makePokemonTile(name));
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
window.addEventListener("load", () => {
|