phase 1-6 implemented
This commit is contained in:
1 parent
22c274bb83
commit
2c4927478a
73 files changed
+9702
-2354
No files matched your search
@@ -17,6 +17,7 @@ import { AnimatedButton } from "../../components/AnimatedButton";
|
||||
import { GradientBackground } from "../../components/GradientBackground";
|
||||
import { useState, useEffect } from "react";
|
||||
import { API_BASE_URL, API_ENDPOINTS } from "../../config/api";
|
||||
import log from "../../utils/logger";
|
||||
|
||||
export default function ProfileScreen() {
|
||||
const { user } = useUser();
|
||||
@@ -27,7 +28,7 @@ export default function ProfileScreen() {
|
||||
try {
|
||||
await signOut();
|
||||
} catch (err) {
|
||||
console.error("Error signing out:", err);
|
||||
log.error("Failed to sign out", err);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -69,26 +70,32 @@ export default function ProfileScreen() {
|
||||
setGymsLoading(true);
|
||||
const token = await getToken();
|
||||
const url = `${API_BASE_URL}${API_ENDPOINTS.GYMS}`;
|
||||
console.log("Profile.loadGyms fetching:", url);
|
||||
log.debug("Loading gyms", { url });
|
||||
const res = await fetch(url, {
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : undefined,
|
||||
});
|
||||
const contentType = res.headers.get("content-type") || "";
|
||||
if (!res.ok) {
|
||||
const text = await res.text().catch(() => "");
|
||||
console.error("Failed to fetch gyms: non-OK response", {
|
||||
status: res.status,
|
||||
body: text?.slice(0, 200),
|
||||
});
|
||||
log.error(
|
||||
"Failed to fetch gyms - non-OK response",
|
||||
new Error(text.slice(0, 200)),
|
||||
{
|
||||
status: res.status,
|
||||
},
|
||||
);
|
||||
setGyms([]);
|
||||
return;
|
||||
}
|
||||
if (!contentType.includes("application/json")) {
|
||||
const text = await res.text().catch(() => "");
|
||||
console.error("Failed to fetch gyms: expected JSON", {
|
||||
contentType,
|
||||
body: text?.slice(0, 200),
|
||||
});
|
||||
log.error(
|
||||
"Failed to fetch gyms - expected JSON",
|
||||
new Error(text.slice(0, 200)),
|
||||
{
|
||||
contentType,
|
||||
},
|
||||
);
|
||||
setGyms([]);
|
||||
return;
|
||||
}
|
||||
@@ -97,12 +104,9 @@ export default function ProfileScreen() {
|
||||
data = await res.json();
|
||||
} catch (e) {
|
||||
const text = await res.text().catch(() => "");
|
||||
console.error(
|
||||
"Failed to parse gyms JSON:",
|
||||
e,
|
||||
"body:",
|
||||
text?.slice(0, 200),
|
||||
);
|
||||
log.error("Failed to parse gyms JSON", e, {
|
||||
bodyPreview: text?.slice(0, 200),
|
||||
});
|
||||
setGyms([]);
|
||||
return;
|
||||
}
|
||||
@@ -119,7 +123,7 @@ export default function ProfileScreen() {
|
||||
if (selectedGymId === null) setSelectedGymId(gid);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Failed to fetch gyms:", err);
|
||||
log.error("Failed to fetch gyms", err);
|
||||
setGyms([]);
|
||||
} finally {
|
||||
setGymsLoading(false);
|
||||
@@ -130,12 +134,7 @@ export default function ProfileScreen() {
|
||||
try {
|
||||
const token = await getToken();
|
||||
const url = `${API_BASE_URL}${API_ENDPOINTS.USERS}/gym`;
|
||||
console.log(
|
||||
"Profile.handleApplyGym PATCH:",
|
||||
url,
|
||||
"gymId:",
|
||||
selectedGymId,
|
||||
);
|
||||
log.debug("Updating gym selection", { url, gymId: selectedGymId });
|
||||
const res = await fetch(url, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
@@ -147,25 +146,25 @@ export default function ProfileScreen() {
|
||||
const contentType = res.headers.get("content-type") || "";
|
||||
if (!res.ok) {
|
||||
const text = await res.text().catch(() => "");
|
||||
console.error("Failed to update gym selection: non-OK response", {
|
||||
status: res.status,
|
||||
body: text?.slice(0, 200),
|
||||
});
|
||||
log.error(
|
||||
"Failed to update gym selection - non-OK response",
|
||||
new Error(text.slice(0, 200)),
|
||||
{
|
||||
status: res.status,
|
||||
},
|
||||
);
|
||||
Alert.alert("Error", "Failed to update gym selection");
|
||||
return;
|
||||
}
|
||||
if (contentType.includes("application/json")) {
|
||||
try {
|
||||
const data = await res.json();
|
||||
console.log("Gym selection updated:", data);
|
||||
log.debug("Gym selection updated", { data });
|
||||
} catch (e) {
|
||||
const text = await res.text().catch(() => "");
|
||||
console.error(
|
||||
"Failed to parse update response JSON:",
|
||||
e,
|
||||
"body:",
|
||||
text?.slice(0, 200),
|
||||
);
|
||||
log.error("Failed to parse update response JSON", e, {
|
||||
bodyPreview: text?.slice(0, 200),
|
||||
});
|
||||
}
|
||||
}
|
||||
// Update current gym state for immediate UI reflection
|
||||
@@ -179,14 +178,14 @@ export default function ProfileScreen() {
|
||||
try {
|
||||
await (user as any)?.reload?.();
|
||||
} catch (e) {
|
||||
console.log("Profile.handleApplyGym: failed to reload user", e);
|
||||
log.debug("Failed to reload user after gym update", { error: e });
|
||||
}
|
||||
Alert.alert(
|
||||
"Success",
|
||||
selectedGymId ? "Gym selected successfully" : "Proceeding without gym",
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("Failed to update gym selection:", err);
|
||||
log.error("Failed to update gym selection", err);
|
||||
Alert.alert("Error", "Failed to update gym selection");
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user