summaryrefslogtreecommitdiff
path: root/hi-ui/src/routes/(app)/+layout.svelte
diff options
context:
space:
mode:
authorKit La Touche <kit@transneptune.net>2024-10-09 15:32:52 -0400
committerKit La Touche <kit@transneptune.net>2024-10-09 15:32:52 -0400
commitbd53a51af835478d23bef4772ce7e50553dc3fdf (patch)
tree3f190a47b9f704c412d0ff684b959abf003b8e5b /hi-ui/src/routes/(app)/+layout.svelte
parentdd62b823e01934a0f841256fdb17b551091896bf (diff)
Move a lot of things around
Diffstat (limited to 'hi-ui/src/routes/(app)/+layout.svelte')
-rw-r--r--hi-ui/src/routes/(app)/+layout.svelte95
1 files changed, 95 insertions, 0 deletions
diff --git a/hi-ui/src/routes/(app)/+layout.svelte b/hi-ui/src/routes/(app)/+layout.svelte
new file mode 100644
index 0000000..98d4acf
--- /dev/null
+++ b/hi-ui/src/routes/(app)/+layout.svelte
@@ -0,0 +1,95 @@
+<script>
+ import { onMount } from 'svelte';
+
+ import { boot, subscribeToEvents } from '$lib/apiServer';
+ import { currentUser, 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,
+ }));
+ let channels = boot.channels.map((channel) => ({
+ id: channel.id,
+ name: channel.name,
+ }));
+ channelsList.update((value) => value.setChannels(channels));
+ let bootMessages = boot.channels.map((channel) => [channel.id, channel.messages]);
+ for (let [channel, channelMessages] of bootMessages) {
+ messages.update((value) => value.addMessages(channel, channelMessages));
+ }
+ }
+
+ 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&hellip;</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: 89vh;
+ 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>