blob: 94ef98a278a988a42dcecd36194916a032211b09 (
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
34
35
36
37
38
39
40
41
42
43
44
45
46
|
<script>
import { tick } from 'svelte';
import { postToChannel } from '$lib/apiServer';
export let channel = null;
let input;
let value = '';
let pending = false;
$: disabled = pending || channel === null;
async function handleSubmit() {
if (channel !== null) {
pending = true;
// TODO try/catch:
await postToChannel(channel, value);
pending = false;
value = '';
await tick();
input.focus();
}
}
function onKeyDown(event) {
if (!event.altKey && event.key === 'Enter') {
handleSubmit();
event.preventDefault();
}
}
</script>
<form on:submit|preventDefault={handleSubmit} class="flex flex-row flex-nowrap">
<textarea
bind:this={input}
bind:value
{disabled}
on:keydown={onKeyDown}
type="search"
class="flex-auto h-6 input rounded-r-none"
/>
<button
color="primary variant-filled-secondary"
type="submit"
class="flex-none w-6 h-6 btn-icon variant-filled rounded-l-none">»</button
>
</form>
|