mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 02:00:31 +08:00
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>
40 lines
1008 B
Svelte
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>
|