summaryrefslogtreecommitdiff
path: root/hi-ui/src/lib/components/MessageInput.svelte
diff options
context:
space:
mode:
authorKit La Touche <kit@transneptune.net>2024-10-09 15:32:52 -0400
committerKit La Touche <kit@transneptune.net>2024-10-09 15:32:52 -0400
commitbd53a51af835478d23bef4772ce7e50553dc3fdf (patch)
tree3f190a47b9f704c412d0ff684b959abf003b8e5b /hi-ui/src/lib/components/MessageInput.svelte
parentdd62b823e01934a0f841256fdb17b551091896bf (diff)
Move a lot of things around
Diffstat (limited to 'hi-ui/src/lib/components/MessageInput.svelte')
-rw-r--r--hi-ui/src/lib/components/MessageInput.svelte30
1 files changed, 30 insertions, 0 deletions
diff --git a/hi-ui/src/lib/components/MessageInput.svelte b/hi-ui/src/lib/components/MessageInput.svelte
new file mode 100644
index 0000000..b33574b
--- /dev/null
+++ b/hi-ui/src/lib/components/MessageInput.svelte
@@ -0,0 +1,30 @@
+<script>
+ import { tick } from 'svelte';
+ import { postToChannel } from '$lib/apiServer';
+ import { activeChannel } from '$lib/store';
+
+ let input;
+ let value;
+ let disabled;
+ activeChannel.subscribe((value) => {
+ disabled = !value.isSet();
+ if (input && !disabled) {
+ input.focus();
+ }
+ });
+
+ async function handleSubmit(event) {
+ disabled = true;
+ // TODO try/catch:
+ await postToChannel($activeChannel.get(), value);
+ value = '';
+ disabled = false;
+ await tick();
+ input.focus();
+ }
+</script>
+
+<form on:submit|preventDefault={handleSubmit} class="flex flex-row flex-nowrap">
+ <input bind:this={input} bind:value={value} disabled={disabled} 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">&raquo;</button>
+</form>