diff options
| author | Kit La Touche <kit@transneptune.net> | 2024-10-30 16:50:06 -0400 |
|---|---|---|
| committer | Kit La Touche <kit@transneptune.net> | 2024-10-30 16:50:06 -0400 |
| commit | 113096a2cca42008c0a19110abe322180dbdf66b (patch) | |
| tree | cb871dae060e60be7fd2114ee4741027ae38bd78 /ui | |
| parent | 610f6839d2e449d172aa6ac35e6c1de0677a0754 (diff) | |
| parent | 06c839436900ce07ec5c53175b01f3c5011e507c (diff) | |
Merge branch 'main' into wip/mobile
Diffstat (limited to 'ui')
| -rw-r--r-- | ui/lib/apiServer.js | 4 | ||||
| -rw-r--r-- | ui/lib/components/CurrentUser.svelte (renamed from ui/lib/components/LogOut.svelte) | 2 | ||||
| -rw-r--r-- | ui/lib/components/Invite.svelte | 41 | ||||
| -rw-r--r-- | ui/lib/components/Invites.svelte | 28 | ||||
| -rw-r--r-- | ui/routes/(app)/me/+page.svelte | 41 | ||||
| -rw-r--r-- | ui/routes/+layout.svelte | 7 |
6 files changed, 85 insertions, 38 deletions
diff --git a/ui/lib/apiServer.js b/ui/lib/apiServer.js index db554e2..19dcf60 100644 --- a/ui/lib/apiServer.js +++ b/ui/lib/apiServer.js @@ -30,6 +30,10 @@ export async function logOut() { return apiServer.post('/auth/logout', {}); } +export async function changePassword(password, to) { + return apiServer.post('/password', { password, to }); +} + export async function createChannel(name) { return apiServer.post('/channels', { name }); } diff --git a/ui/lib/components/LogOut.svelte b/ui/lib/components/CurrentUser.svelte index ba0861a..4b1b974 100644 --- a/ui/lib/components/LogOut.svelte +++ b/ui/lib/components/CurrentUser.svelte @@ -14,7 +14,7 @@ <form on:submit|preventDefault={handleLogout}> {#if $currentUser} - @{$currentUser.username} + <a href="/me">@{$currentUser.username}</a> {/if} <button class="border-slate-500 border-solid border-2 font-bold p-1 rounded" diff --git a/ui/lib/components/Invite.svelte b/ui/lib/components/Invite.svelte index f4babad..7fdc753 100644 --- a/ui/lib/components/Invite.svelte +++ b/ui/lib/components/Invite.svelte @@ -1,40 +1,13 @@ <script> - import { base } from '$app/paths'; - import { createInvite } from '$lib/apiServer'; import { clipboard } from '@skeletonlabs/skeleton'; - let invite = null; - $: inviteUrl = invite ? new URL(`/invite/${invite.id}`, document.location) : null; - $: inviteUrl, console.log("invite url", inviteUrl); + export let id; + $: inviteUrl = new URL(`/invite/${id}`, document.location); +</script> - async function onSubmit() { - let response = await createInvite(); - if (response.status == 200) { - invite = response.data; - } - console.log("base url", base); - } +<button + class="border-slate-500 border-solid border-2 font-bold p-1 rounded" + use:clipboard={inviteUrl}>Copy</button> +<span data-clipboard="inviteUrl">{inviteUrl}</span> - async function onReset() { - invite = null; - } -</script> -<form - on:submit|preventDefault={onSubmit} - on:reset|preventDefault={onReset}> - {#if inviteUrl} - <button - class="border-slate-500 border-solid border-2 font-bold p-1 rounded" - use:clipboard={inviteUrl} - type="reset"> - Copy Invite - </button> - {:else} - <button - class="border-slate-500 border-solid border-2 font-bold p-1 rounded" - type="submit"> - Invite - </button> - {/if} -</form> diff --git a/ui/lib/components/Invites.svelte b/ui/lib/components/Invites.svelte new file mode 100644 index 0000000..df51afb --- /dev/null +++ b/ui/lib/components/Invites.svelte @@ -0,0 +1,28 @@ +<script> + import { writable } from 'svelte/store'; + import { createInvite } from '$lib/apiServer'; + import Invite from '$lib/components/Invite.svelte'; + + let invites = writable([]); + $: $invites, console.log("invites", $invites); + + async function onSubmit() { + let response = await createInvite(); + if (response.status == 200) { + invites.update(val => [...val, response.data]); + } + } +</script> + +<ul> + {#each $invites as invite} + <li><Invite id={invite.id} /></li> + {/each} +</ul> +<form on:submit|preventDefault={onSubmit}> + <button + class="btn variant-filled" + type="submit"> + Create Invitation + </button> +</form> diff --git a/ui/routes/(app)/me/+page.svelte b/ui/routes/(app)/me/+page.svelte new file mode 100644 index 0000000..7559dbe --- /dev/null +++ b/ui/routes/(app)/me/+page.svelte @@ -0,0 +1,41 @@ +<script> + import { changePassword } from '$lib/apiServer.js'; + + import Invites from '$lib/components/Invites.svelte'; + + let currentPassword, newPassword, confirmPassword, passwordForm; + let pending = false; + $: valid = (newPassword === confirmPassword) && (newPassword !== currentPassword); + $: disabled = pending || !valid; + + async function onPasswordChange() { + pending = true; + let response = await changePassword(currentPassword, newPassword); + switch (response.status) { + case 200: + passwordForm.reset(); + break; + } + pending = false; + } +</script> + +<form on:submit|preventDefault={onPasswordChange} bind:this={passwordForm} > + <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 variant-filled" type="submit" disabled={disabled}> + change password + </button> +</form> + +<Invites /> diff --git a/ui/routes/+layout.svelte b/ui/routes/+layout.svelte index b7ed746..4133ff3 100644 --- a/ui/routes/+layout.svelte +++ b/ui/routes/+layout.svelte @@ -1,12 +1,13 @@ <script> - import { AppBar } from '@skeletonlabs/skeleton'; import "../app.css"; - import logo from '$lib/assets/logo.png'; + import { AppBar } from '@skeletonlabs/skeleton'; import { showMenu, currentUser } from '$lib/store'; - import LogOut from '$lib/components/LogOut.svelte'; + + 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); |
