fix searchbar for real
This commit is contained in:
parent
c8a38cdd83
commit
8a99e9837e
@ -1,4 +1,4 @@
|
|||||||
import { Throttler } from "./utils";
|
import { Throttler } from "./Throttler";
|
||||||
|
|
||||||
type Position = {
|
type Position = {
|
||||||
x: number;
|
x: number;
|
||||||
@ -105,7 +105,7 @@ function setupSearchBar(zipCodeElement: HTMLParagraphElement) {
|
|||||||
searchBar.onkeypress = (event: KeyboardEvent) => {console.log(event);
|
searchBar.onkeypress = (event: KeyboardEvent) => {console.log(event);
|
||||||
event.key !== "Enter" || !isNaN(parseInt(event.key));}
|
event.key !== "Enter" || !isNaN(parseInt(event.key));}
|
||||||
|
|
||||||
searchBar.addEventListener("submit", async (event: MouseEvent) => {
|
searchBar.addEventListener("submit", async (event: SubmitEvent) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
const inputValue = searchInput.value;
|
const inputValue = searchInput.value;
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user