Files
radicle-explorer/src/Search.svelte
T
Rūdolfs Ošiņš 251f9681bc Fix mobile context menu
Refactor and inline the MobileNavbar component into Header. This fixes a
bug where it wasn't possible to close the context menu once it was open.

Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
2022-09-21 11:39:01 +02:00

40 lines
1008 B
Svelte

<script lang="ts">
import { resolve, ResolvedSearch } from "@app/resolver";
import type { Config } from "@app/config";
import { createEventDispatcher } from "svelte";
import Loading from "@app/Loading.svelte";
import TextInput from "@app/TextInput.svelte";
export let config: Config;
let input = "";
let searching = false;
let results: ResolvedSearch | null;
const dispatch = createEventDispatcher();
const handleKeydown = async (event: KeyboardEvent) => {
if (event.key === "Enter") {
searching = true;
results = await resolve(input, config);
if (results) {
dispatch("search", { query: input, results });
}
input = "";
searching = false;
dispatch("finished");
}
};
</script>
<TextInput
variant="dashed"
bind:value={input}
on:keydown={handleKeydown}
placeholder="Search a name or address…">
<svelte:fragment slot="right">
{#if searching}
<Loading small />
{/if}
</svelte:fragment>
</TextInput>