diff --git a/packages/frontend/src/Account.tsx b/packages/frontend/src/Account.tsx index 69246ed..614d86e 100644 --- a/packages/frontend/src/Account.tsx +++ b/packages/frontend/src/Account.tsx @@ -4,11 +4,13 @@ import { SettingsPageLayout } from "@/components/settings-page-layout"; import { Button } from "@/components/ui/button"; import { Field } from "@/components/ui/field"; import { Label } from "@/components/ui/label"; +import { UploadAvatar } from "@/components/upload-avatar"; import { user } from "@/lib/server"; function Account() { const [name, setName] = useState(""); const [password, setPassword] = useState(""); + const [avatarURL, setAvatarUrl] = useState(null); const [error, setError] = useState(""); const [submitAttempted, setSubmitAttempted] = useState(false); const [userId, setUserId] = useState(null); @@ -19,6 +21,7 @@ function Account() { const user = JSON.parse(userStr) as UserRecord; setName(user.name); setUserId(user.id); + setAvatarUrl(user.avatarURL || null); } }, []); @@ -39,6 +42,7 @@ function Account() { id: userId, name: name.trim(), password: password.trim(), + avatarURL: avatarURL || undefined, onSuccess: (data) => { setError(""); localStorage.setItem("user", JSON.stringify(data)); @@ -52,7 +56,11 @@ function Account() { return ( -
+ +
+ + +
(null); const [error, setError] = useState(""); const [submitAttempted, setSubmitAttempted] = useState(false); @@ -59,6 +61,7 @@ export default function LogInForm() { name, username, password, + avatarURL, }), }) .then(async (res) => { @@ -83,7 +86,7 @@ export default function LogInForm() { }; const focusFirstInput = () => { - const firstInput = document.querySelector("input"); + const firstInput = document.querySelector('input[type="text"]'); if (firstInput) { (firstInput as HTMLInputElement).focus(); } @@ -96,6 +99,7 @@ export default function LogInForm() { const resetForm = () => { setError(""); setSubmitAttempted(false); + setAvatarUrl(null); requestAnimationFrame(() => focusFirstInput()); }; @@ -119,32 +123,41 @@ export default function LogInForm() { )} > - {capitalise(mode)} + {capitalise(mode)} - {mode === "register" && ( +
+ {mode === "register" && ( + <> + + setName(e.target.value)} + validate={(v) => (v.trim() === "" ? "Cannot be empty" : undefined)} + submitAttempted={submitAttempted} + /> + + )} setName(e.target.value)} + label="Username" + value={username} + onChange={(e) => setUsername(e.target.value)} validate={(v) => (v.trim() === "" ? "Cannot be empty" : undefined)} submitAttempted={submitAttempted} /> - )} - setUsername(e.target.value)} - validate={(v) => (v.trim() === "" ? "Cannot be empty" : undefined)} - submitAttempted={submitAttempted} - /> - setPassword(e.target.value)} - validate={(v) => (v.trim() === "" ? "Cannot be empty" : undefined)} - hidden={true} - submitAttempted={submitAttempted} - /> + setPassword(e.target.value)} + validate={(v) => (v.trim() === "" ? "Cannot be empty" : undefined)} + hidden={true} + submitAttempted={submitAttempted} + /> +
{mode === "login" ? ( <> diff --git a/packages/frontend/src/components/upload-avatar.tsx b/packages/frontend/src/components/upload-avatar.tsx index a8467be..fe34d99 100644 --- a/packages/frontend/src/components/upload-avatar.tsx +++ b/packages/frontend/src/components/upload-avatar.tsx @@ -2,15 +2,18 @@ import { useRef, useState } from "react"; import { Button } from "@/components/ui/button"; import { Label } from "@/components/ui/label"; import { user } from "@/lib/server"; +import { cn } from "@/lib/utils"; export function UploadAvatar({ avatarURL, onAvatarUploaded, label, + className, }: { avatarURL?: string | null; onAvatarUploaded: (avatarURL: string) => void; label?: string; + className?: string; }) { const [uploading, setUploading] = useState(false); const [error, setError] = useState(null); @@ -37,7 +40,7 @@ export function UploadAvatar({ }; return ( -
+
{avatarURL && ( Avatar )}