diff options
Diffstat (limited to 'hi-ui/src/lib/MessageInput.svelte')
| -rw-r--r-- | hi-ui/src/lib/MessageInput.svelte | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/hi-ui/src/lib/MessageInput.svelte b/hi-ui/src/lib/MessageInput.svelte index 96e9577..938e467 100644 --- a/hi-ui/src/lib/MessageInput.svelte +++ b/hi-ui/src/lib/MessageInput.svelte @@ -1,27 +1,25 @@ <script> + import { tick } from 'svelte'; import { postToChannel } from '../apiServer'; import { activeChannel } from '../store'; + let self; let input; - let disabled = false; - let activeChannelId; - - activeChannel.subscribe((value) => { - activeChannelId = value ? value.id : null; - }); + $: disabled = $activeChannel == null; async function handleSubmit(event) { - event.preventDefault(); disabled = true; // TODO try/catch: - await postToChannel(activeChannelId, input); + await postToChannel($activeChannel?.id, input); input = ''; disabled = false; + await tick(); + self.focus(); } </script> -<form on:submit={handleSubmit}> - <input type="text" class="border rounded px-3" bind:value={input} disabled={disabled}> +<form on:submit|preventDefault={handleSubmit}> + <input type="text" class="border rounded px-3" bind:this={self} bind:value={input} disabled={disabled}> <button type="submit">➤</button> </form> |
