summaryrefslogtreecommitdiff
path: root/hi-ui/src/routes
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-05 18:17:25 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-05 18:17:25 -0400
commit0c0cd1daa0c6640e81bb6282ae4a1c574cf135f4 (patch)
treed6b4195cc7be249fb55cb1160f01db0a6daa84f1 /hi-ui/src/routes
parent54a542df2164e421e78b48d7229a6bfabbc5c26b (diff)
parent40cc35bcc9b881a61ca62c67e107bb17c2748f57 (diff)
Merge branch 'wip/ui'
Diffstat (limited to 'hi-ui/src/routes')
-rw-r--r--hi-ui/src/routes/+layout.svelte20
-rw-r--r--hi-ui/src/routes/+page.svelte82
2 files changed, 102 insertions, 0 deletions
diff --git a/hi-ui/src/routes/+layout.svelte b/hi-ui/src/routes/+layout.svelte
new file mode 100644
index 0000000..67a5fa5
--- /dev/null
+++ b/hi-ui/src/routes/+layout.svelte
@@ -0,0 +1,20 @@
+<script>
+ import "../app.css";
+
+ export const ssr = false;
+</script>
+
+<div id="app">
+ <h1>hi</h1>
+
+ <slot />
+</div>
+
+<style>
+ #app {
+ margin: 0;
+ padding: 1rem;
+ height: 100vh;
+ width: 100%;
+ }
+</style>
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&hellip;</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>