summaryrefslogtreecommitdiff
path: root/ui/routes
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-11 01:18:18 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-11 01:18:18 -0400
commit72f3d8c5ab3e2a42cf1a76d0c08815dbe46e50a1 (patch)
tree2b582e5319ac377649379851f8f5910517ca2a72 /ui/routes
parent2e2e3980ab78052be74f4007c343e69a583648fe (diff)
Move login to its own route.
This - in passing - fixes the problem where the client failed to subscribe after logging in, by causing the whole subscription process to be re-run when returning to the main interface.
Diffstat (limited to 'ui/routes')
-rw-r--r--ui/routes/(app)/+layout.svelte24
-rw-r--r--ui/routes/(login)/login/+page.svelte5
2 files changed, 18 insertions, 11 deletions
diff --git a/ui/routes/(app)/+layout.svelte b/ui/routes/(app)/+layout.svelte
index 1d561ae..0f8e83c 100644
--- a/ui/routes/(app)/+layout.svelte
+++ b/ui/routes/(app)/+layout.svelte
@@ -1,22 +1,19 @@
<script>
- import { onMount } from 'svelte';
import { page } from '$app/stores';
+ import { goto } from '$app/navigation';
+ import { onMount, onDestroy } from 'svelte';
import { boot, subscribeToEvents } from '$lib/apiServer';
import { currentUser, logins, channelsList, messages } from '$lib/store';
import ChannelList from '$lib/components/ChannelList.svelte';
import CreateChannelForm from '$lib/components/CreateChannelForm.svelte';
- import LogIn from '$lib/components/LogIn.svelte';
import MessageInput from '$lib/components/MessageInput.svelte';
- let user;
let loading = true;
- $: channel = $page?.params?.channel;
+ let events = null;
- currentUser.subscribe((value) => {
- user = value;
- });
+ $: channel = $page?.params?.channel;
function onBooted(boot) {
currentUser.update(() => ({
@@ -34,10 +31,11 @@
switch (response.status) {
case 200:
onBooted(response.data);
- subscribeToEvents(response.data.resume_point);
+ events = subscribeToEvents(response.data.resume_point);
break;
case 401:
currentUser.update(() => null);
+ goto('/login');
break;
default:
// TODO: display error.
@@ -48,11 +46,17 @@
}
loading = false;
});
+
+ onDestroy(async () => {
+ if (events !== null) {
+ events.close();
+ }
+ });
</script>
{#if loading}
<h2>Loading&hellip;</h2>
-{:else if user != null}
+{:else}
<div id="interface">
<div class="channel-list">
<ChannelList active={channel} />
@@ -67,8 +71,6 @@
<MessageInput {channel} />
</div>
</div>
-{:else}
- <LogIn />
{/if}
<style>
diff --git a/ui/routes/(login)/login/+page.svelte b/ui/routes/(login)/login/+page.svelte
new file mode 100644
index 0000000..c333fdd
--- /dev/null
+++ b/ui/routes/(login)/login/+page.svelte
@@ -0,0 +1,5 @@
+<script>
+ import LogIn from '$lib/components/LogIn.svelte';
+</script>
+
+<LogIn />