summaryrefslogtreecommitdiff
path: root/hi-ui/src/lib/MessageInput.svelte
diff options
context:
space:
mode:
Diffstat (limited to 'hi-ui/src/lib/MessageInput.svelte')
-rw-r--r--hi-ui/src/lib/MessageInput.svelte31
1 files changed, 31 insertions, 0 deletions
diff --git a/hi-ui/src/lib/MessageInput.svelte b/hi-ui/src/lib/MessageInput.svelte
new file mode 100644
index 0000000..938e467
--- /dev/null
+++ b/hi-ui/src/lib/MessageInput.svelte
@@ -0,0 +1,31 @@
+<script>
+ import { tick } from 'svelte';
+ import { postToChannel } from '../apiServer';
+ import { activeChannel } from '../store';
+
+ let self;
+ let input;
+ $: disabled = $activeChannel == null;
+
+ async function handleSubmit(event) {
+ disabled = true;
+ // TODO try/catch:
+ await postToChannel($activeChannel?.id, input);
+ input = '';
+ disabled = false;
+ await tick();
+ self.focus();
+ }
+</script>
+
+<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>
+
+<style>
+ input[type="text"] {
+ /* TODO: percentage won't handle zoom in/out well. */
+ width: 96%;
+ }
+</style>