diff options
Diffstat (limited to 'ui/src/routes')
| -rw-r--r-- | ui/src/routes/(app)/+layout.svelte | 89 | ||||
| -rw-r--r-- | ui/src/routes/(app)/+page.svelte | 0 | ||||
| -rw-r--r-- | ui/src/routes/(app)/ch/[channel]/+page.svelte | 17 | ||||
| -rw-r--r-- | ui/src/routes/+layout.js | 1 | ||||
| -rw-r--r-- | ui/src/routes/+layout.svelte | 30 |
5 files changed, 137 insertions, 0 deletions
diff --git a/ui/src/routes/(app)/+layout.svelte b/ui/src/routes/(app)/+layout.svelte new file mode 100644 index 0000000..f8744c1 --- /dev/null +++ b/ui/src/routes/(app)/+layout.svelte @@ -0,0 +1,89 @@ +<script> + import { onMount } 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; + + currentUser.subscribe((value) => { + user = value; + }); + + function onBooted(boot) { + currentUser.update(() => ({ + id: boot.login.id, + username: boot.login.name, + })); + logins.update((value) => value.setLogins(boot.logins)); + channelsList.update((value) => value.setChannels(boot.channels)); + messages.update((value) => value.setMessages(boot.messages)); + } + + onMount(async () => { + try { + let response = await boot(); + switch (response.status) { + case 200: + onBooted(response.data); + subscribeToEvents(response.data.resume_point); + break; + case 401: + currentUser.update(() => null); + break; + default: + // TODO: display error. + break; + } + } catch (_) { + // I don't want exceptions on non-200 series responses, dammit. + } + loading = false; + }); +</script> + +{#if loading} + <h2>Loading…</h2> +{:else if user != null} + <div id="interface"> + <div class="channel-list"> + <ChannelList /> + </div> + <div class="active-channel"> + <slot /> + </div> + <div class="create-channel"> + <CreateChannelForm /> + </div> + <div class="create-message"> + <MessageInput /> + </div> + </div> +{:else} + <LogIn /> +{/if} + +<style> + #interface { + height: 88vh; + margin: 1rem; + display: grid; + grid-template-columns: 18rem auto; + grid-template-rows: auto 2rem; + grid-gap: 0.25rem; + } + #interface div { + max-height: 100%; + overflow: scroll; + } + #interface .active-channel { + border: 1px solid grey; + border-radius: 1.25rem; + } +</style> diff --git a/ui/src/routes/(app)/+page.svelte b/ui/src/routes/(app)/+page.svelte new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ui/src/routes/(app)/+page.svelte diff --git a/ui/src/routes/(app)/ch/[channel]/+page.svelte b/ui/src/routes/(app)/ch/[channel]/+page.svelte new file mode 100644 index 0000000..ef439d0 --- /dev/null +++ b/ui/src/routes/(app)/ch/[channel]/+page.svelte @@ -0,0 +1,17 @@ +<script> + import { afterNavigate } from '$app/navigation'; + import { page } from '$app/stores'; + + import { activeChannel } from '$lib/store'; + import ActiveChannel from '$lib/components/ActiveChannel.svelte'; + + afterNavigate(async () => { + let { channel } = $page.params; + activeChannel.update((value) => { + value.set(channel) + return value; + }); + }); +</script> + +<ActiveChannel /> diff --git a/ui/src/routes/+layout.js b/ui/src/routes/+layout.js new file mode 100644 index 0000000..a3d1578 --- /dev/null +++ b/ui/src/routes/+layout.js @@ -0,0 +1 @@ +export const ssr = false; diff --git a/ui/src/routes/+layout.svelte b/ui/src/routes/+layout.svelte new file mode 100644 index 0000000..7b99d62 --- /dev/null +++ b/ui/src/routes/+layout.svelte @@ -0,0 +1,30 @@ +<script> + import { AppBar } from '@skeletonlabs/skeleton'; + import "../app.css"; + + import { currentUser } from '$lib/store'; + import LogOut from '$lib/components/LogOut.svelte'; +</script> + +<div id="app"> + <AppBar> + <svelte:fragment slot="lead">🌳</svelte:fragment> + <a href="/">understory</a> + <svelte:fragment slot="trail"> + {#if $currentUser} + <LogOut /> + {/if} + </svelte:fragment> + </AppBar> + + <slot /> +</div> + +<style> + #app { + margin: 0; + padding: 1rem; + height: 100vh; + width: 100%; + } +</style> |
