diff options
| -rwxr-xr-x | tools/run | 14 | ||||
| -rw-r--r-- | ui/lib/assets/logo.png | bin | 0 -> 137101 bytes | |||
| -rw-r--r-- | ui/lib/components/Channel.svelte | 8 | ||||
| -rw-r--r-- | ui/lib/components/Message.svelte | 11 | ||||
| -rw-r--r-- | ui/lib/store.js | 1 | ||||
| -rw-r--r-- | ui/routes/(app)/+layout.svelte | 107 | ||||
| -rw-r--r-- | ui/routes/+layout.svelte | 45 | ||||
| -rw-r--r-- | ui/static/favicon.png | bin | 1571 -> 137101 bytes |
8 files changed, 140 insertions, 46 deletions
@@ -1,7 +1,15 @@ #!/bin/bash -e ## tools/run [ARGS...] -## -## Run the server in development mode. Shorthand for `cargo run`. -cargo run -- "$@" +if [ -z ${HI_DEV+x} ]; then + tools/build-ui + cargo run -- "$@" +else + npm run dev & PIDS[0]=$! + cargo run -- "$@" & PIDS[1]=$! + + trap "kill ${PIDS[*]}" SIGINT + + wait +fi diff --git a/ui/lib/assets/logo.png b/ui/lib/assets/logo.png Binary files differnew file mode 100644 index 0000000..5df6b4e --- /dev/null +++ b/ui/lib/assets/logo.png diff --git a/ui/lib/components/Channel.svelte b/ui/lib/components/Channel.svelte index e62f0f3..bbe9ff7 100644 --- a/ui/lib/components/Channel.svelte +++ b/ui/lib/components/Channel.svelte @@ -1,14 +1,20 @@ <script> + import { showMenu } from '$lib/store'; + export let id; export let name; export let active = false; + + function hideMenu() { + showMenu.update(() => false); + } </script> <li class="rounded-full" class:bg-slate-400={active} > -<a href="/ch/{id}"> +<a href="/ch/{id}" on:click={hideMenu}> <span class="badge bg-primary-500">#</span> <span class="flex-auto">{name}</span> </a> diff --git a/ui/lib/components/Message.svelte b/ui/lib/components/Message.svelte index d040433..2705e4b 100644 --- a/ui/lib/components/Message.svelte +++ b/ui/lib/components/Message.svelte @@ -10,9 +10,10 @@ let timestamp = new Date(at).toTimeString(); let name; $: name = $logins.get(sender); + $: ownMessage = $currentUser.id == sender; </script> -<div class="card card-hover m-4 relative"> +<div class="card card-hover m-4 relative" class:own-message={ownMessage} class:other-message={!ownMessage}> <span class="chip variant-soft sticky top-o left-0"> <!-- TODO: should this show up for only the first of a run? --> @{name}: @@ -30,4 +31,12 @@ .card:hover .timestamp { display: flex; } + .own-message { + width: 80%; + margin-right: auto; + } + .other-message { + width: 80%; + margin-left: auto; + } </style> diff --git a/ui/lib/store.js b/ui/lib/store.js index ae17ffa..bdd3e3b 100644 --- a/ui/lib/store.js +++ b/ui/lib/store.js @@ -3,6 +3,7 @@ import { Channels } from '$lib/store/channels'; import { Messages } from '$lib/store/messages'; import { Logins } from '$lib/store/logins'; +export const showMenu = writable(false); export const currentUser = writable(null); export const logins = writable(new Logins()); export const channelsList = writable(new Channels()); diff --git a/ui/routes/(app)/+layout.svelte b/ui/routes/(app)/+layout.svelte index 08c6694..9fcdf41 100644 --- a/ui/routes/(app)/+layout.svelte +++ b/ui/routes/(app)/+layout.svelte @@ -4,7 +4,7 @@ import { onMount, onDestroy } from 'svelte'; import { boot, subscribeToEvents } from '$lib/apiServer'; - import { currentUser, logins, channelsList, messages } from '$lib/store'; + import { showMenu, currentUser, logins, channelsList, messages } from '$lib/store'; import ChannelList from '$lib/components/ChannelList.svelte'; import CreateChannelForm from '$lib/components/CreateChannelForm.svelte'; @@ -12,6 +12,15 @@ let loading = true; let events = null; + let showMenuValue; + showMenu.subscribe((value) => { + showMenuValue = value; + }); + + + function toggleMenu() { + showMenu.update((value) => !value); + } $: channel = $page?.params?.channel; @@ -54,36 +63,82 @@ }); </script> +<svelte:head> + <title>understory</title> +</svelte:head> + {#if loading} <h2>Loading…</h2> {:else} - <div id="interface"> - <div class="channel-list"> - <ChannelList active={channel} /> - </div> - <div class="active-channel"> - <slot /> - </div> - <div class="create-channel"> - <CreateChannelForm /> - </div> - <div class="create-message"> - <MessageInput {channel} /> - </div> + <div id="interface" class="p-2"> + <main> + <div class="active-channel border border-solid border-gray-400 rounded-[1.25rem]"> + <slot /> + </div> + <div class="create-message overflow-scroll max-h-full"> + <MessageInput {channel} /> + </div> + </main> + + <nav id="sidebar" data-expanded={showMenuValue}> + <button class="h-4 w-4" aria-controls="sidebar" aria-expanded={showMenuValue} on:click={toggleMenu}>✖</button> + <div class="channel-list"> + <ChannelList active={channel} /> + </div> + <div class="create-channel"> + <CreateChannelForm /> + </div> + </nav> </div> {/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; - } +:root { + --app-bar-height: 68px; + --input-row-height: 2rem; +} + +#interface { + margin: unset; + display: grid; + grid-template: + 'side main' 1fr + / auto 1fr + ; + + @media (width > 640px) { + --overlay: static; + --translate: 0; + } +} +nav { + grid-area: side; + background-color: rgb(var(--color-surface-600)); + inset: auto auto 0 0; + padding: 0.25rem; + position: var(--overlay, absolute); + transition: translate 300ms ease-out; + height: calc(100vh - var(--app-bar-height)); + width: 21rem; +} +nav button { + position: absolute; + top: 0; + right: 0; +} +main { + grid-area: main; + height: calc(100vh - var(--app-bar-height)); +} +.active-channel { + height: calc(100vh - var(--app-bar-height) - var(--input-row-height)); + overflow: scroll; +} +.channel-list { + height: calc(100vh - var(--app-bar-height) - var(--input-row-height)); + overflow: scroll; +} +nav[data-expanded=false] { + translate: var(--translate, -100% 0); +} </style> diff --git a/ui/routes/+layout.svelte b/ui/routes/+layout.svelte index 711b8bd..4133ff3 100644 --- a/ui/routes/+layout.svelte +++ b/ui/routes/+layout.svelte @@ -1,21 +1,36 @@ <script> - import { AppBar } from '@skeletonlabs/skeleton'; - import "../app.css"; + import "../app.css"; + import logo from '$lib/assets/logo.png'; - import { currentUser } from '$lib/store'; - import CurrentUser from '$lib/components/CurrentUser.svelte'; + import { AppBar } from '@skeletonlabs/skeleton'; + import { showMenu, currentUser } from '$lib/store'; + + import CurrentUser from '$lib/components/CurrentUser.svelte'; + import Invite from '$lib/components/Invite.svelte'; + import LogOut from '$lib/components/LogOut.svelte'; + + function toggleMenu() { + showMenu.update((value) => !value); + } </script> -<div id="app"> - <AppBar> - <svelte:fragment slot="lead">🌳</svelte:fragment> - <a href="/">understory</a> - <svelte:fragment slot="trail"> - {#if $currentUser} - <CurrentUser /> - {/if} - </svelte:fragment> - </AppBar> +<div id="app" class="m-0 p-0 h-vh w-full"> + <div class="w-full"> + <AppBar class="app-bar"> + <svelte:fragment slot="lead"> + <a on:click|preventDefault={toggleMenu} class="cursor-pointer"> + <img class="w-8 h-8" alt="logo" src={logo} /> + </a> + </svelte:fragment> + <a href="/">understory</a> + <svelte:fragment slot="trail"> + {#if $currentUser} + <Invite /> + <LogOut /> + {/if} + </svelte:fragment> + </AppBar> + </div> <slot /> </div> @@ -23,7 +38,7 @@ <style> #app { margin: 0; - padding: 1rem; + padding: 0; height: 100vh; width: 100%; } diff --git a/ui/static/favicon.png b/ui/static/favicon.png Binary files differindex 825b9e6..5df6b4e 100644 --- a/ui/static/favicon.png +++ b/ui/static/favicon.png |
