From 504c1025a53b5f9cd88272ffbbeb9eb5f9d3aa64 Mon Sep 17 00:00:00 2001 From: Tiago Yamamoto Date: Fri, 26 Dec 2025 12:30:16 -0300 Subject: [PATCH] debug: Add console logs to homepage to trace job data source --- frontend/src/app/page.tsx | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index 09a2a25..f31517c 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -25,6 +25,8 @@ export default function HomePage() { async function fetchFeaturedJobs() { try { const apiBase = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8521" + console.log("[DEBUG] API Base URL:", apiBase) + const mapJobs = (jobs: any[]): Job[] => jobs.map((j: any) => ({ id: String(j.id), @@ -39,33 +41,50 @@ export default function HomePage() { isFeatured: j.isFeatured })) + console.log("[DEBUG] Fetching featured jobs from:", `${apiBase}/api/v1/jobs?featured=true&limit=6`) const featuredRes = await fetch(`${apiBase}/api/v1/jobs?featured=true&limit=6`) + console.log("[DEBUG] Featured response status:", featuredRes.status) + if (!featuredRes.ok) throw new Error("Failed to fetch featured jobs") const featuredData = await featuredRes.json() + console.log("[DEBUG] Featured data from API:", featuredData) + const featuredList = featuredData.data ? mapJobs(featuredData.data) : [] + console.log("[DEBUG] Mapped featured jobs:", featuredList.length, "jobs") if (featuredList.length === 6) { + console.log("[DEBUG] Using featured jobs only (6 found)") setFeaturedJobs(featuredList) return } + console.log("[DEBUG] Fetching fallback jobs from:", `${apiBase}/api/v1/jobs?limit=6`) const fallbackRes = await fetch(`${apiBase}/api/v1/jobs?limit=6`) + console.log("[DEBUG] Fallback response status:", fallbackRes.status) + if (!fallbackRes.ok) throw new Error("Failed to fetch fallback jobs") const fallbackData = await fallbackRes.json() + console.log("[DEBUG] Fallback data from API:", fallbackData) + const fallbackList = fallbackData.data ? mapJobs(fallbackData.data) : [] + console.log("[DEBUG] Mapped fallback jobs:", fallbackList.length, "jobs") const combined = [...featuredList, ...fallbackList].slice(0, 6) + console.log("[DEBUG] Combined jobs:", combined.length, "jobs") + if (combined.length === 6) { + console.log("[DEBUG] Using combined jobs (6)") setFeaturedJobs(combined) } else if (combined.length > 0) { + console.log("[DEBUG] Using combined jobs (less than 6)") setFeaturedJobs(combined) } else { + console.log("[DEBUG] ⚠️ USING MOCK DATA - No API jobs found!") setFeaturedJobs(mockJobs.slice(0, 6)) } } catch (error) { - console.error("Error fetching featured jobs:", error) - // Fallback to mock data if API fails? Or just empty. - // For MVP let's leave empty or maybe keep mock as fallback if needed. + console.error("[DEBUG] ❌ Error fetching featured jobs:", error) + console.log("[DEBUG] ⚠️ USING MOCK DATA due to error") setFeaturedJobs(mockJobs.slice(0, 6)) } finally { setLoading(false)