diff --git a/frontend/src/lib/components/Energy/EmptyFoodComp.svelte b/frontend/src/lib/components/Energy/EmptyFoodComp.svelte index cc92ce1..7e457d3 100644 --- a/frontend/src/lib/components/Energy/EmptyFoodComp.svelte +++ b/frontend/src/lib/components/Energy/EmptyFoodComp.svelte @@ -4,7 +4,6 @@ import { CreateFood, GetLastPer100 } from "$wails/main/App"; import { foodStore } from "$lib/store/Energy/foodStore"; import FoodSearchEntry from "./FoodSearchEntry.svelte"; - import { onMount } from "svelte"; let item: main.Food = { food: "", @@ -28,6 +27,7 @@ // Maybe it would be a good idea to use $ instead of update down there... // Maybe it's a topic for another day $: { + name = name.trim(); if (!name) { foodSearch = []; } @@ -72,27 +72,33 @@ if (!per100Edited) GetLastPer100(name.trim()).then((res) => { - if (res.success && res.data) { + // Prevent search when there's nothing to search + // Sometimes we get search results after deleting name + if (res.success && res.data && name) { foodSearch = res.data; + } else { + foodSearch = []; } }); } let hiLiteIndex: number | null = null; - function navigateList(e: KeyboardEvent) { - if (e.key === "ArrowDown" && hiLiteIndex && hiLiteIndex <= foodSearch.length - 1) { - hiLiteIndex === null ? (hiLiteIndex = 0) : (hiLiteIndex += 1); - } else if (e.key === "ArrowUp" && hiLiteIndex !== null) { - hiLiteIndex === 0 ? (hiLiteIndex = foodSearch.length - 1) : (hiLiteIndex -= 1); - } else if (e.key === "Enter") { - // @ts-ignore ITS NOT NULL YOU ASSHAT - // WE CHECKED - // ITS NOT - setInputVal(foodSearch[hiLiteIndex]); - } else { - return; - } - } + // function navigateList(e: KeyboardEvent) { + // console.log(foodSearch, hiLiteIndex); + // // @ts-ignore shut the fuck up + // if (e.key == "ArrowDown" && hiLiteIndex <= foodSearch.length - 2) { + // hiLiteIndex == null ? (hiLiteIndex = 0) : (hiLiteIndex += 1); + // } else if (e.key == "ArrowUp" && hiLiteIndex !== null) { + // hiLiteIndex == 0 ? 0 : (hiLiteIndex -= 1); + // } else if (e.key == "Enter") { + // // @ts-ignore ITS NOT NULL YOU ASSHAT + // // WE CHECKED + // // ITS NOT + // setInputVal(foodSearch[hiLiteIndex]); + // } else { + // return; + // } + // } function setInputVal(val: string) { name = val; hiLiteIndex = null; @@ -108,12 +114,15 @@ } + +