diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-10-10 22:30:18 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-10-10 23:08:36 -0400 |
| commit | 2e2e3980ab78052be74f4007c343e69a583648fe (patch) | |
| tree | e791f18ee018a504db6da4939a8b82d1d84fe725 /ui/lib/components | |
| parent | 1798988c5bc6ad8c2286848df14c7fa478e135d1 (diff) | |
Compute the active channel from the current routing state, not from a store.
Diffstat (limited to 'ui/lib/components')
| -rw-r--r-- | ui/lib/components/ActiveChannel.svelte | 7 | ||||
| -rw-r--r-- | ui/lib/components/Channel.svelte | 8 | ||||
| -rw-r--r-- | ui/lib/components/ChannelList.svelte | 8 | ||||
| -rw-r--r-- | ui/lib/components/MessageInput.svelte | 30 |
4 files changed, 22 insertions, 31 deletions
diff --git a/ui/lib/components/ActiveChannel.svelte b/ui/lib/components/ActiveChannel.svelte index 978e952..ece9f55 100644 --- a/ui/lib/components/ActiveChannel.svelte +++ b/ui/lib/components/ActiveChannel.svelte @@ -1,10 +1,11 @@ <script> - import { activeChannel, messages } from '$lib/store'; + import { messages } from '$lib/store'; import Message from './Message.svelte'; - let container; - $: messageList = $activeChannel.isSet() ? $messages.inChannel($activeChannel.get()) : []; + export let channel = null; + $: messageList = channel !== null ? $messages.inChannel(channel) : []; + let container; // TODO: eventually, store scroll height/last unread in channel? scroll there? let scroll = (message) => { diff --git a/ui/lib/components/Channel.svelte b/ui/lib/components/Channel.svelte index 97fea1f..e62f0f3 100644 --- a/ui/lib/components/Channel.svelte +++ b/ui/lib/components/Channel.svelte @@ -1,13 +1,7 @@ <script> - import { activeChannel } from '$lib/store'; - export let id; export let name; - let active = false; - - activeChannel.subscribe((value) => { - active = value.is(id); - }); + export let active = false; </script> <li diff --git a/ui/lib/components/ChannelList.svelte b/ui/lib/components/ChannelList.svelte index e0e5f06..316e404 100644 --- a/ui/lib/components/ChannelList.svelte +++ b/ui/lib/components/ChannelList.svelte @@ -2,17 +2,15 @@ import { channelsList } from '$lib/store'; import Channel from './Channel.svelte'; - let channels; + export let active = null; - channelsList.subscribe((value) => { - channels = value.channels; - }); + $: channels = $channelsList.channels; </script> <nav class="list-nav"> <ul> {#each channels as channel} - <Channel {...channel} /> + <Channel {...channel} active={active === channel.id} /> {/each} </ul> </nav> diff --git a/ui/lib/components/MessageInput.svelte b/ui/lib/components/MessageInput.svelte index b33574b..0da78d4 100644 --- a/ui/lib/components/MessageInput.svelte +++ b/ui/lib/components/MessageInput.svelte @@ -1,30 +1,28 @@ <script> import { tick } from 'svelte'; import { postToChannel } from '$lib/apiServer'; - import { activeChannel } from '$lib/store'; + export let channel = null; let input; let value; - let disabled; - activeChannel.subscribe((value) => { - disabled = !value.isSet(); - if (input && !disabled) { + let sending = false; + + $: disabled = (channel === null); + + async function handleSubmit() { + if (channel !== null) { + sending = true; + // TODO try/catch: + await postToChannel(channel, value); + sending = false; + value = ''; + await tick(); 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" /> + <input bind:this={input} bind:value={value} disabled={sending || 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">»</button> </form> |
