From 9f0ba2e243be772a7677f8250893f5da7b2acbfe Mon Sep 17 00:00:00 2001
From: Owen Jacobson <owen@grimoire.ca>
Date: Wed, 6 Nov 2024 17:42:02 -0500
Subject: Factor out the elements of the `/me` page, and style them a little.

---
 ui/routes/(app)/me/+page.svelte | 84 ++++++-----------------------------------
 1 file changed, 11 insertions(+), 73 deletions(-)

(limited to 'ui/routes/(app)/me/+page.svelte')

diff --git a/ui/routes/(app)/me/+page.svelte b/ui/routes/(app)/me/+page.svelte
index 8d24a61..e02bde5 100644
--- a/ui/routes/(app)/me/+page.svelte
+++ b/ui/routes/(app)/me/+page.svelte
@@ -1,79 +1,17 @@
 <script>
-  import { goto } from '$app/navigation';
-  import { changePassword, logOut } from '$lib/apiServer.js';
-  import { currentUser } from '$lib/store';
-
+  import LogOut from '$lib/components/LogOut.svelte';
   import Invites from '$lib/components/Invites.svelte';
-
-  let currentPassword = $state(''),
-    newPassword = $state(''),
-    confirmPassword = $state(''),
-    passwordForm;
-  let pending = $state(false);
-  let valid = $derived(newPassword === confirmPassword && newPassword !== currentPassword);
-  let disabled = $derived(pending || !valid);
-
-  async function onLogOut(event) {
-    event.preventDefault();
-    const response = await logOut();
-    if (200 <= response.status && response.status < 300) {
-      currentUser.update(() => null);
-      goto('/login');
-    }
-  }
-
-  async function onPasswordChange(event) {
-    event.preventDefault();
-    pending = true;
-    let response = await changePassword(currentPassword, newPassword);
-    switch (response.status) {
-      case 200:
-        passwordForm.reset();
-        break;
-    }
-    pending = false;
-  }
+  import ChangePassword from '$lib/components/ChangePassword.svelte';
 </script>
 
-<form onsubmit={onLogOut}>
-  <button class="btn variant-filled" type="submit">log out</button>
-</form>
-
-<form onsubmit={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>
+<div class="my-4">
+  <ChangePassword />
+</div>
 
-  <button class="btn variant-filled" type="submit" {disabled}> change password </button>
-</form>
+<div class="my-4">
+  <Invites />
+</div>
 
-<Invites />
+<div class="my-4">
+  <LogOut />
+</div>
-- 
cgit v1.2.3

