From 4a899f63e8ec40a4d20afb0126ad2913748b4f85 Mon Sep 17 00:00:00 2001 From: ectasy663 Date: Thu, 9 Jul 2026 17:53:27 +0530 Subject: [PATCH] Fix Admin test upload API endpoint URL & fix AI coach infinite reload caused by session polling --- src/app/admin/tests/page.tsx | 4 ++-- src/hooks/useActiveUser.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/admin/tests/page.tsx b/src/app/admin/tests/page.tsx index 54413ff..a78a561 100644 --- a/src/app/admin/tests/page.tsx +++ b/src/app/admin/tests/page.tsx @@ -27,7 +27,7 @@ export default function AdminTestsPage() { const fetchTests = async () => { try { - const res = await fetch("http://localhost:8000/api/admin/tests") + const res = await fetch("/api/admin/tests") if (res.ok) { const data = await res.json() setTests(data) @@ -83,7 +83,7 @@ export default function AdminTestsPage() { }; try { - const res = await fetch("http://localhost:8000/api/admin/tests/create_manual", { + const res = await fetch("/api/admin/tests/upload", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) diff --git a/src/hooks/useActiveUser.ts b/src/hooks/useActiveUser.ts index 3b08bac..799dbdf 100644 --- a/src/hooks/useActiveUser.ts +++ b/src/hooks/useActiveUser.ts @@ -41,8 +41,8 @@ export function useActiveUser() { const [loading, setLoading] = useState(true); const [error, setError] = useState(null); - const fetchUserProfile = useCallback(async (id: string) => { - setLoading(true); + const fetchUserProfile = useCallback(async (id: string, isPoll: boolean = false) => { + if (!isPoll) setLoading(true); setError(null); try { const res = await fetch(`/api/users/${id}`); @@ -71,7 +71,7 @@ export function useActiveUser() { console.error("Error fetching active user profile:", err); setError(err.message || "Failed to load user"); } finally { - setLoading(false); + if (!isPoll) setLoading(false); } }, []); @@ -90,7 +90,7 @@ export function useActiveUser() { // Poll every 10 seconds for session validity const interval = setInterval(() => { - fetchUserProfile(userId); + fetchUserProfile(userId, true); }, 10000); return () => {