fix searchbar for real

This commit is contained in:
Mikkel 2023-02-07 14:18:50 +01:00
parent c8a38cdd83
commit 8a99e9837e
2 changed files with 2 additions and 19 deletions

View File

@ -1,4 +1,4 @@
import { Throttler } from "./utils";
import { Throttler } from "./Throttler";
type Position = {
x: number;
@ -105,7 +105,7 @@ function setupSearchBar(zipCodeElement: HTMLParagraphElement) {
searchBar.onkeypress = (event: KeyboardEvent) => {console.log(event);
event.key !== "Enter" || !isNaN(parseInt(event.key));}
searchBar.addEventListener("submit", async (event: MouseEvent) => {
searchBar.addEventListener("submit", async (event: SubmitEvent) => {
event.preventDefault();
const inputValue = searchInput.value;

View File

@ -1,17 +0,0 @@
export class Throttler {
private hasBeenCalledWithinTime = false;
private lastCallFunc: (() => any) | null = null;
public constructor(private minimumTimeBetweenCall: number) {}
public call(func: () => any) {
this.lastCallFunc = func;
if (this.hasBeenCalledWithinTime) return;
this.hasBeenCalledWithinTime = true;
func();
setTimeout(() => {
this.hasBeenCalledWithinTime = false;
if (this.lastCallFunc) this.lastCallFunc();
}, this.minimumTimeBetweenCall);
}
}