v3: code quality pass
This commit is contained in:
@@ -13,11 +13,12 @@ import {
|
||||
deserializeAuthResponse,
|
||||
deserializeDump,
|
||||
deserializePublicUser,
|
||||
deserializeUser,
|
||||
hydrateDump,
|
||||
hydratePlaylist,
|
||||
parseAPIResponse,
|
||||
type RawDump,
|
||||
type RawUser,
|
||||
type RawPublicUser,
|
||||
type UpdateUserRequest,
|
||||
} from "../model.ts";
|
||||
import { Avatar } from "../components/Avatar.tsx";
|
||||
import { DumpCard } from "../components/DumpCard.tsx";
|
||||
@@ -478,28 +479,24 @@ export function UserPublicProfile() {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
const body = await res.json() as {
|
||||
success: boolean;
|
||||
data?: RawUser;
|
||||
error?: { message: string };
|
||||
};
|
||||
const body = parseAPIResponse<RawPublicUser>(await res.json());
|
||||
|
||||
if (!res.ok || !body.success) {
|
||||
setAvatarError(body.error?.message ?? "Upload failed");
|
||||
if (!body.success) {
|
||||
setAvatarError(body.error.message);
|
||||
return;
|
||||
}
|
||||
|
||||
const storedRaw = localStorage.getItem("authResponse");
|
||||
if (storedRaw && body.data) {
|
||||
if (storedRaw) {
|
||||
login({
|
||||
...deserializeAuthResponse(JSON.parse(storedRaw)),
|
||||
user: deserializeUser(body.data),
|
||||
user: deserializePublicUser(body.data),
|
||||
});
|
||||
}
|
||||
|
||||
setState((prev) =>
|
||||
prev.status === "loaded" && body.data
|
||||
? { ...prev, user: deserializeUser(body.data) }
|
||||
prev.status === "loaded"
|
||||
? { ...prev, user: deserializePublicUser(body.data) }
|
||||
: prev
|
||||
);
|
||||
} catch {
|
||||
@@ -517,11 +514,16 @@ export function UserPublicProfile() {
|
||||
try {
|
||||
const res = await authFetch(`${API_URL}/api/users/me`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({ description: descDraft.trim() }),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(
|
||||
{
|
||||
description: descDraft.trim() || undefined,
|
||||
} satisfies UpdateUserRequest,
|
||||
),
|
||||
});
|
||||
const body = await res.json();
|
||||
if (!res.ok || !body.success) {
|
||||
setDescError(body.error?.message ?? "Failed to save");
|
||||
const body = parseAPIResponse<RawPublicUser>(await res.json());
|
||||
if (!body.success) {
|
||||
setDescError(body.error.message);
|
||||
return;
|
||||
}
|
||||
setState((s) =>
|
||||
@@ -949,6 +951,7 @@ function UpvotedDumpList(
|
||||
canVote={canVote}
|
||||
castVote={castVote}
|
||||
removeVote={removeVote}
|
||||
isOwner={isOwnProfile}
|
||||
className={extraCls}
|
||||
/>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user