diff options
Diffstat (limited to 'hi-ui/src/lib')
| -rw-r--r-- | hi-ui/src/lib/ActiveChannel.svelte | 20 | ||||
| -rw-r--r-- | hi-ui/src/lib/MessageInput.svelte | 17 |
2 files changed, 31 insertions, 6 deletions
diff --git a/hi-ui/src/lib/ActiveChannel.svelte b/hi-ui/src/lib/ActiveChannel.svelte index 42aa53f..680a785 100644 --- a/hi-ui/src/lib/ActiveChannel.svelte +++ b/hi-ui/src/lib/ActiveChannel.svelte @@ -1,15 +1,27 @@ <script> - import { activeChannel } from '../store'; + import { activeChannel, events } from '../store'; - let channelName; + let channel; + let allMessages = []; + $: messages = allMessages.filter( + (ev) => ev.type === 'message' && channel !== null && ev.channel.id === channel.id + ); activeChannel.subscribe((value) => { - channelName = value ? value.name : 'none'; + channel = value; + }); + + events.subscribe((value) => { + allMessages = value; }); </script> <div> - Active channel: {channelName} + {#each messages as message} + <div> + <pre><tt>{message.at} @{message.sender.name}: {message.message.body}</tt></pre> + </div> + {/each} </div> <style> diff --git a/hi-ui/src/lib/MessageInput.svelte b/hi-ui/src/lib/MessageInput.svelte index 4bb4aab..96e9577 100644 --- a/hi-ui/src/lib/MessageInput.svelte +++ b/hi-ui/src/lib/MessageInput.svelte @@ -1,9 +1,22 @@ <script> + import { postToChannel } from '../apiServer'; + import { activeChannel } from '../store'; + let input; let disabled = false; + let activeChannelId; + + activeChannel.subscribe((value) => { + activeChannelId = value ? value.id : null; + }); - function handleSubmit(event) { - console.log(event); + async function handleSubmit(event) { + event.preventDefault(); + disabled = true; + // TODO try/catch: + await postToChannel(activeChannelId, input); + input = ''; + disabled = false; } </script> |
