diff options
Diffstat (limited to 'ui/lib')
| -rw-r--r-- | ui/lib/apiServer.js | 4 | ||||
| -rw-r--r-- | ui/lib/assets/logo.png | bin | 137101 -> 92469 bytes | |||
| -rw-r--r-- | ui/lib/components/ActiveChannel.svelte | 18 | ||||
| -rw-r--r-- | ui/lib/components/ChangePassword.svelte | 60 | ||||
| -rw-r--r-- | ui/lib/components/Invite.svelte | 5 | ||||
| -rw-r--r-- | ui/lib/components/Invites.svelte | 13 | ||||
| -rw-r--r-- | ui/lib/components/LogOut.svelte | 18 | ||||
| -rw-r--r-- | ui/lib/components/Message.svelte | 32 | ||||
| -rw-r--r-- | ui/lib/components/MessageInput.svelte | 2 | ||||
| -rw-r--r-- | ui/lib/components/MessageRun.svelte | 6 | ||||
| -rw-r--r-- | ui/lib/store/messages.svelte.js | 17 |
11 files changed, 142 insertions, 33 deletions
diff --git a/ui/lib/apiServer.js b/ui/lib/apiServer.js index 6ada0f7..fee1a81 100644 --- a/ui/lib/apiServer.js +++ b/ui/lib/apiServer.js @@ -34,6 +34,10 @@ export async function postToChannel(channelId, body) { return apiServer.post(`/channels/${channelId}`, { body }); } +export async function deleteMessage(messageId) { + return apiServer.delete(`/messages/${messageId}`, {}); +} + export async function createInvite() { return apiServer.post(`/invite`, {}); } diff --git a/ui/lib/assets/logo.png b/ui/lib/assets/logo.png Binary files differindex 5df6b4e..4b35d9b 100644 --- a/ui/lib/assets/logo.png +++ b/ui/lib/assets/logo.png diff --git a/ui/lib/components/ActiveChannel.svelte b/ui/lib/components/ActiveChannel.svelte index f939dbd..ba62d6c 100644 --- a/ui/lib/components/ActiveChannel.svelte +++ b/ui/lib/components/ActiveChannel.svelte @@ -4,16 +4,8 @@ let { messageRuns } = $props(); </script> -<div class="container"> - {#each messageRuns as { sender, messages }} - <div> - <MessageRun {sender} {messages} /> - </div> - {/each} -</div> - -<style> - .container { - overflow: auto; - } -</style> +{#each messageRuns as { sender, messages }} + <div> + <MessageRun {sender} {messages} /> + </div> +{/each} diff --git a/ui/lib/components/ChangePassword.svelte b/ui/lib/components/ChangePassword.svelte new file mode 100644 index 0000000..1e48bee --- /dev/null +++ b/ui/lib/components/ChangePassword.svelte @@ -0,0 +1,60 @@ +<script> + import { changePassword } from '$lib/apiServer.js'; + + let currentPassword = $state(''), + newPassword = $state(''), + confirmPassword = $state(''), + pending = $state(false), + form; + let valid = $derived(newPassword === confirmPassword && newPassword !== currentPassword); + let disabled = $derived(pending || !valid); + + async function onsubmit(event) { + event.preventDefault(); + pending = true; + let response = await changePassword(currentPassword, newPassword); + switch (response.status) { + case 200: + form.reset(); + break; + } + pending = false; + } +</script> + +<form {onsubmit} bind:this={form}> + <label + >current password + <input + class="input" + name="currentPassword" + type="password" + placeholder="password" + bind:value={currentPassword} + /> + </label> + + <label + >new password + <input + class="input" + name="newPassword" + type="password" + placeholder="password" + bind:value={newPassword} + /> + </label> + + <label + >confirm new password + <input + class="input" + name="confirmPassword" + type="password" + placeholder="password" + bind:value={confirmPassword} + /> + </label> + + <button class="btn bg-orange-500 mt-4" type="submit" {disabled}>change password</button> +</form> diff --git a/ui/lib/components/Invite.svelte b/ui/lib/components/Invite.svelte index 35e00b4..937c911 100644 --- a/ui/lib/components/Invite.svelte +++ b/ui/lib/components/Invite.svelte @@ -5,8 +5,5 @@ let inviteUrl = $derived(new URL(`/invite/${id}`, document.location)); </script> -<button - class="border-slate-500 border-solid border-2 font-bold p-1 rounded" - use:clipboard={inviteUrl}>Copy</button -> +<button class="btn bg-secondary-500" use:clipboard={inviteUrl}>copy</button> <span data-clipboard="inviteUrl">{inviteUrl}</span> diff --git a/ui/lib/components/Invites.svelte b/ui/lib/components/Invites.svelte index cc14f3b..493bf1c 100644 --- a/ui/lib/components/Invites.svelte +++ b/ui/lib/components/Invites.svelte @@ -4,7 +4,7 @@ let invites = $state([]); - async function onSubmit(event) { + async function onsubmit(event) { event.preventDefault(); let response = await createInvite(); if (response.status == 200) { @@ -13,11 +13,12 @@ } </script> -<ul> +<form {onsubmit}> + <button class="btn bg-primary-500" type="submit">create invitation</button> +</form> + +<ul class="mt-4"> {#each invites as invite} - <li><Invite id={invite.id} /></li> + <li class="my-1"><Invite id={invite.id} /></li> {/each} </ul> -<form onsubmit={onSubmit}> - <button class="btn variant-filled" type="submit"> Create Invitation </button> -</form> diff --git a/ui/lib/components/LogOut.svelte b/ui/lib/components/LogOut.svelte new file mode 100644 index 0000000..25dd5e9 --- /dev/null +++ b/ui/lib/components/LogOut.svelte @@ -0,0 +1,18 @@ +<script> + import { goto } from '$app/navigation'; + import { logOut } from '$lib/apiServer.js'; + import { currentUser } from '$lib/store'; + + async function onsubmit(event) { + event.preventDefault(); + const response = await logOut(); + if (200 <= response.status && response.status < 300) { + currentUser.update(() => null); + goto('/login'); + } + } +</script> + +<form {onsubmit}> + <button class="btn bg-orange-400" type="submit">log out</button> +</form> diff --git a/ui/lib/components/Message.svelte b/ui/lib/components/Message.svelte index 68c5c91..0c8eeec 100644 --- a/ui/lib/components/Message.svelte +++ b/ui/lib/components/Message.svelte @@ -2,16 +2,38 @@ import { marked } from 'marked'; import DOMPurify from 'dompurify'; + import { deleteMessage } from '$lib/apiServer'; + function scroll(message) { message.scrollIntoView(); } - let { at, body } = $props(); + let { id, at, body, editable = false } = $props(); let renderedBody = $derived(DOMPurify.sanitize(marked.parse(body, { breaks: true }))); + let deleteArmed = $state(false); + + function onDelete(event) { + event.preventDefault(); + if (deleteArmed) { + deleteArmed = false; + deleteMessage(id); + } else { + deleteArmed = true; + } + } + + function onmouseleave() { + deleteArmed = false; + } </script> -<div class="message relative"> - <span class="timestamp chip variant-soft absolute top-0 right-0">{at}</span> +<div class="message relative" class:bg-warning-800={deleteArmed} {onmouseleave}> + <div class="handle chip bg-surface-700 absolute -top-6 right-0"> + {at} + {#if editable} + <button onclick={onDelete}>🗑️</button> + {/if} + </div> <section use:scroll class="py-1 message-body"> <!-- eslint-disable-next-line svelte/no-at-html-tags --> {@html renderedBody} @@ -19,10 +41,10 @@ </div> <style> - .message .timestamp { + .message .handle { display: none; } - .message:hover .timestamp { + .message:hover .handle { display: flex; } .message-body { diff --git a/ui/lib/components/MessageInput.svelte b/ui/lib/components/MessageInput.svelte index c071bea..26521e1 100644 --- a/ui/lib/components/MessageInput.svelte +++ b/ui/lib/components/MessageInput.svelte @@ -31,7 +31,7 @@ bind:value {disabled} type="search" - class="flex-auto h-6 input rounded-r-none" + class="flex-auto h-6 py-0 input rounded-r-none text-nowrap" ></textarea> <button color="primary variant-filled-secondary" diff --git a/ui/lib/components/MessageRun.svelte b/ui/lib/components/MessageRun.svelte index b71e972..83a82a9 100644 --- a/ui/lib/components/MessageRun.svelte +++ b/ui/lib/components/MessageRun.svelte @@ -9,14 +9,14 @@ </script> <div - class="card m-4 px-4 py-1 relative" + class="card my-4 px-4 py-1 relative" class:own-message={ownMessage} class:other-message={!ownMessage} > <span class="chip variant-soft sticky top-o left-0"> @{name}: </span> - {#each messages as { at, body }} - <Message {at} {body} /> + {#each messages as { id, at, body }} + <Message {id} {at} {body} editable={ownMessage} /> {/each} </div> diff --git a/ui/lib/store/messages.svelte.js b/ui/lib/store/messages.svelte.js index 2442675..c0db71b 100644 --- a/ui/lib/store/messages.svelte.js +++ b/ui/lib/store/messages.svelte.js @@ -11,7 +11,20 @@ export class Messages { let parsedAt = new Date(at); const message = { id, at: parsedAt, body }; - let runs = (this.channels[channel] ||= []); + // You might be thinking, can't this be + // + // let runs = (this.channels[channel] ||= []); + // + // Let me tell you, I thought that too. Javascript's semantics allow it. It + // didn't work - the first message in each channel was getting lost as the + // update to `this.channels` wasn't actually happening. I suspect this is + // due to the implementation of Svelte's `$state` rune, but I don't know it + // for sure. + // + // In any case, splitting the read and write up like this has the same + // semantics, and _works_. (This time, for sure!) + let runs = this.channels[channel] || []; + let currentRun = runs.slice(-1)[0]; if (currentRun === undefined) { currentRun = { sender, messages: [message] }; @@ -29,6 +42,8 @@ export class Messages { } } + this.channels[channel] = runs; + return this; } |
