diff options
Diffstat (limited to 'hi-ui/src/routes/+page.svelte')
| -rw-r--r-- | hi-ui/src/routes/+page.svelte | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/hi-ui/src/routes/+page.svelte b/hi-ui/src/routes/+page.svelte new file mode 100644 index 0000000..66b4f8d --- /dev/null +++ b/hi-ui/src/routes/+page.svelte @@ -0,0 +1,82 @@ +<script> + import { onMount } from 'svelte'; + + import { boot, subscribeToEvents } from '../apiServer'; + import { currentUser } from '../store'; + + import ActiveChannel from '../lib/ActiveChannel.svelte'; + import ChannelList from '../lib/ChannelList.svelte'; + import CreateChannelForm from '../lib/CreateChannelForm.svelte'; + import LogIn from '../lib/LogIn.svelte'; + import LogOut from '../lib/LogOut.svelte'; + import MessageInput from '../lib/MessageInput.svelte'; + + let user; + let loading = true; + + currentUser.subscribe((value) => { + user = value; + }); + + onMount(async () => { + try { + let response = await boot(); + switch (response.status) { + case 200: + currentUser.update(() => ({ + username: response.data.login.name, + id: response.data.login.id, + })); + subscribeToEvents(); + 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} + <LogOut /> + <div id="interface"> + <div> + <ChannelList /> + </div> + <div> + <ActiveChannel /> + </div> + <div> + <CreateChannelForm /> + </div> + <div> + <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; + border: 1px solid grey; + } +</style> |
