summaryrefslogtreecommitdiff
path: root/hi-ui/src/lib/MessageInput.svelte
blob: 96e9577176e52ea30ca7e32f0bc7ee6311b4b407 (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
32
33
<script>
    import { postToChannel } from '../apiServer';
    import { activeChannel } from '../store';

    let input;
    let disabled = false;
    let activeChannelId;

    activeChannel.subscribe((value) => {
        activeChannelId = value ? value.id : null;
    });

    async function handleSubmit(event) {
        event.preventDefault();
        disabled = true;
        // TODO try/catch:
        await postToChannel(activeChannelId, input);
        input = '';
        disabled = false;
    }
</script>

<form on:submit={handleSubmit}>
    <input type="text" class="border rounded px-3" bind:value={input} disabled={disabled}>
    <button type="submit">➤</button>
</form>

<style>
    input[type="text"] {
        /* TODO: percentage won't handle zoom in/out well. */
        width: 96%;
    }
</style>