Explorar o código

Clean up search logic and fix math padding

Kirk Trombley %!s(int64=3) %!d(string=hai) anos
pai
achega
f092034105
Modificáronse 2 ficheiros con 11 adicións e 5 borrados
  1. 1 1
      nearest.css
  2. 10 4
      nearest.js

+ 1 - 1
nearest.css

@@ -43,7 +43,7 @@ body {
 .math-section {
     border: 4px solid #222;
     padding: 1em;
-    padding-bottom: 0;
+    padding-bottom: 0.2em;
     min-width: 90%;
     align-self: center;
 }

+ 10 - 4
nearest.js

@@ -156,6 +156,12 @@ const onUpdate = (event) => {
   const pokemonName = document.getElementById("pokemon-name")?.value?.toLowerCase() ?? "";
   const colorInput = "#" + (document.getElementById("color-input")?.value?.replace("#", "") ?? "FFFFFF");
 
+  // Clear pokemon search
+  if (pokemonName.length === 0) {
+    const searchList = document.getElementById("search-list");
+    searchList.innerHTML = '';
+  }
+
   // Check if parameters have changed
   const newParams = paramsChanged(includeX, normQY, closeCoeff, useRGB, numPoke, colorInput);
 
@@ -225,10 +231,10 @@ const onUpdate = (event) => {
     }
   }
 
-  // Lookup by name
-  const searchList = document.getElementById("search-list");
-  searchList.innerHTML = '';
-  if (pokemonName.length > 0 && (lastPkmnSearch !== pokemonName || newParams)) {
+  // Lookup by name  
+  if (lastPkmnSearch !== pokemonName || newParams) {
+    const searchList = document.getElementById("search-list");
+    searchList.innerHTML = '';
     pokemonLookup
       .search(pokemonName, { limit: 10 })
       // If scoring is impossible, totalScorer will just be identity