summaryrefslogtreecommitdiff
path: root/hi-ui/src/lib/MessageInput.svelte
blob: b899221f2a55d3a1b2e66b46401309ccbe98be43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<script>
    import { Input, ButtonGroup, Button } from 'flowbite-svelte';
    import { CaretRightSolid } from 'flowbite-svelte-icons';

    import { tick } from 'svelte';
    import { postToChannel } from '../apiServer';
    import { activeChannel } from '../store';

    let self;
    let input;
    $: disabled = !$activeChannel.isSet();

    async function handleSubmit(event) {
        disabled = true;
        // TODO try/catch:
        await postToChannel($activeChannel.get(), input);
        input = '';
        disabled = false;
        await tick();
        self.focus();
    }
</script>

<form on:submit|preventDefault={handleSubmit} class="w-full">
    <ButtonGroup>
        <Input disabled={disabled} bind:this={self} bind:value={input} />
        <Button color="primary" type="submit">
            <CaretRightSolid class="w-5 h-5" />
        </Button>
    </ButtonGroup>
</form>