Skip to content

Commit

Permalink
Add debounce to email input
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyfallWasTaken committed Aug 26, 2024
1 parent 1347499 commit dd7de0c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions frontend/src/lib/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
export const debounce = (callback: Function, wait = 300) => {
let timeout: ReturnType<typeof setTimeout>;

return (...args: unknown[]) => {
clearTimeout(timeout);
timeout = setTimeout(() => callback(...args), wait);
};
};
7 changes: 6 additions & 1 deletion frontend/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
import { username } from '$lib/stores/mailbox';
import { ofetch } from 'ofetch';
import { goto } from '$app/navigation';
import { debounce } from '$lib/util';
const emailDomain = import.meta.env.VITE_EMAIL_DOMAIN as string;
function refreshPage() {
goto(window.location.href);
}
function setUsername(event: KeyboardEvent) {
username.set((event.target as HTMLInputElement).value);
}
</script>

<svelte:head>
Expand All @@ -30,7 +35,7 @@
<p class="text-xl font-semibold">You are...</p>
<div class="input-group input-group-divider grid-cols-[auto_1fr_auto]">
<div class="input-group-shim"><MailIcon size="1.4rem" /></div>
<input type="text" placeholder="shark" bind:value={$username} />
<input type="text" placeholder="shark" on:keyup={debounce(setUsername)} />
<div class="input-group-shim">@{emailDomain}</div>
</div>
</div>
Expand Down

0 comments on commit dd7de0c

Please sign in to comment.