debug: Add console logs to homepage to trace job data source
This commit is contained in:
parent
06924383bb
commit
504c1025a5
1 changed files with 22 additions and 3 deletions
|
|
@ -25,6 +25,8 @@ export default function HomePage() {
|
||||||
async function fetchFeaturedJobs() {
|
async function fetchFeaturedJobs() {
|
||||||
try {
|
try {
|
||||||
const apiBase = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8521"
|
const apiBase = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8521"
|
||||||
|
console.log("[DEBUG] API Base URL:", apiBase)
|
||||||
|
|
||||||
const mapJobs = (jobs: any[]): Job[] =>
|
const mapJobs = (jobs: any[]): Job[] =>
|
||||||
jobs.map((j: any) => ({
|
jobs.map((j: any) => ({
|
||||||
id: String(j.id),
|
id: String(j.id),
|
||||||
|
|
@ -39,33 +41,50 @@ export default function HomePage() {
|
||||||
isFeatured: j.isFeatured
|
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`)
|
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")
|
if (!featuredRes.ok) throw new Error("Failed to fetch featured jobs")
|
||||||
const featuredData = await featuredRes.json()
|
const featuredData = await featuredRes.json()
|
||||||
|
console.log("[DEBUG] Featured data from API:", featuredData)
|
||||||
|
|
||||||
const featuredList = featuredData.data ? mapJobs(featuredData.data) : []
|
const featuredList = featuredData.data ? mapJobs(featuredData.data) : []
|
||||||
|
console.log("[DEBUG] Mapped featured jobs:", featuredList.length, "jobs")
|
||||||
|
|
||||||
if (featuredList.length === 6) {
|
if (featuredList.length === 6) {
|
||||||
|
console.log("[DEBUG] Using featured jobs only (6 found)")
|
||||||
setFeaturedJobs(featuredList)
|
setFeaturedJobs(featuredList)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("[DEBUG] Fetching fallback jobs from:", `${apiBase}/api/v1/jobs?limit=6`)
|
||||||
const fallbackRes = await fetch(`${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")
|
if (!fallbackRes.ok) throw new Error("Failed to fetch fallback jobs")
|
||||||
const fallbackData = await fallbackRes.json()
|
const fallbackData = await fallbackRes.json()
|
||||||
|
console.log("[DEBUG] Fallback data from API:", fallbackData)
|
||||||
|
|
||||||
const fallbackList = fallbackData.data ? mapJobs(fallbackData.data) : []
|
const fallbackList = fallbackData.data ? mapJobs(fallbackData.data) : []
|
||||||
|
console.log("[DEBUG] Mapped fallback jobs:", fallbackList.length, "jobs")
|
||||||
|
|
||||||
const combined = [...featuredList, ...fallbackList].slice(0, 6)
|
const combined = [...featuredList, ...fallbackList].slice(0, 6)
|
||||||
|
console.log("[DEBUG] Combined jobs:", combined.length, "jobs")
|
||||||
|
|
||||||
if (combined.length === 6) {
|
if (combined.length === 6) {
|
||||||
|
console.log("[DEBUG] Using combined jobs (6)")
|
||||||
setFeaturedJobs(combined)
|
setFeaturedJobs(combined)
|
||||||
} else if (combined.length > 0) {
|
} else if (combined.length > 0) {
|
||||||
|
console.log("[DEBUG] Using combined jobs (less than 6)")
|
||||||
setFeaturedJobs(combined)
|
setFeaturedJobs(combined)
|
||||||
} else {
|
} else {
|
||||||
|
console.log("[DEBUG] ⚠️ USING MOCK DATA - No API jobs found!")
|
||||||
setFeaturedJobs(mockJobs.slice(0, 6))
|
setFeaturedJobs(mockJobs.slice(0, 6))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching featured jobs:", error)
|
console.error("[DEBUG] ❌ Error fetching featured jobs:", error)
|
||||||
// Fallback to mock data if API fails? Or just empty.
|
console.log("[DEBUG] ⚠️ USING MOCK DATA due to error")
|
||||||
// For MVP let's leave empty or maybe keep mock as fallback if needed.
|
|
||||||
setFeaturedJobs(mockJobs.slice(0, 6))
|
setFeaturedJobs(mockJobs.slice(0, 6))
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue