summaryrefslogtreecommitdiff
path: root/ui/lib/components
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-11 15:52:42 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-11 15:52:42 -0400
commitd33c8af14c4adc1c15ab048299e06f9f35ae4de6 (patch)
tree5dce8c28876353893dfd4725dcd093afff7e6dff /ui/lib/components
parent7bcfeb08946e64642b33f4b099ff235ba8527697 (diff)
parent72f3d8c5ab3e2a42cf1a76d0c08815dbe46e50a1 (diff)
Merge branch 'wip/login-route'
Diffstat (limited to 'ui/lib/components')
-rw-r--r--ui/lib/components/ActiveChannel.svelte7
-rw-r--r--ui/lib/components/Channel.svelte8
-rw-r--r--ui/lib/components/ChannelList.svelte8
-rw-r--r--ui/lib/components/LogIn.svelte4
-rw-r--r--ui/lib/components/LogOut.svelte8
-rw-r--r--ui/lib/components/MessageInput.svelte32
6 files changed, 32 insertions, 35 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/LogIn.svelte b/ui/lib/components/LogIn.svelte
index 2836e6d..e1cda8a 100644
--- a/ui/lib/components/LogIn.svelte
+++ b/ui/lib/components/LogIn.svelte
@@ -1,4 +1,5 @@
<script>
+ import { goto } from '$app/navigation';
import { logIn } from '$lib/apiServer';
import { currentUser } from '$lib/store';
@@ -6,13 +7,14 @@
let username = '';
let password = '';
- async function handleLogin(event) {
+ async function handleLogin() {
disabled = true;
const response = await logIn(username, password);
if (200 <= response.status && response.status < 300) {
currentUser.update(() => ({ username }));
username = '';
password = '';
+ goto('/');
}
disabled = false;
}
diff --git a/ui/lib/components/LogOut.svelte b/ui/lib/components/LogOut.svelte
index 01bef1b..ba0861a 100644
--- a/ui/lib/components/LogOut.svelte
+++ b/ui/lib/components/LogOut.svelte
@@ -1,17 +1,21 @@
<script>
+ import { goto } from '$app/navigation';
import { logOut} from '$lib/apiServer';
import { currentUser } from '$lib/store';
- async function handleLogout(event) {
+ async function handleLogout() {
const response = await logOut();
if (200 <= response.status && response.status < 300) {
currentUser.update(() => null);
+ goto('/login');
}
}
</script>
<form on:submit|preventDefault={handleLogout}>
- @{$currentUser.username}
+ {#if $currentUser}
+ @{$currentUser.username}
+ {/if}
<button
class="border-slate-500 border-solid border-2 font-bold p-1 rounded"
type="submit"
diff --git a/ui/lib/components/MessageInput.svelte b/ui/lib/components/MessageInput.svelte
index b33574b..b2746e0 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 value = '';
+ 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">&raquo;</button>
</form>