diagnostics: add console logging to fetchQuestions
This commit is contained in:
@@ -78,16 +78,20 @@ export default function Community() {
|
|||||||
const response = await fetch('http://localhost:8080/api/questions');
|
const response = await fetch('http://localhost:8080/api/questions');
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
console.log("API DATA FETCHED:", data);
|
||||||
if (data) {
|
if (data) {
|
||||||
// Merge database questions with static mock data, matching IDs to prevent duplicates
|
// Merge database questions with static mock data, matching IDs to prevent duplicates
|
||||||
const backendIds = new Set(data.map((q: any) => q.id.toString()));
|
const backendIds = new Set(data.map((q: any) => q.id.toString()));
|
||||||
const uniqueMocks = QUESTIONS_DATA.filter(q => !backendIds.has(q.id.toString()));
|
const uniqueMocks = QUESTIONS_DATA.filter(q => !backendIds.has(q.id.toString()));
|
||||||
// Sort backend questions newest first, then append mock questions
|
const merged = [...[...data].reverse(), ...uniqueMocks];
|
||||||
setQuestions([...[...data].reverse(), ...uniqueMocks]);
|
console.log("MERGED QUESTIONS LIST:", merged);
|
||||||
|
setQuestions(merged);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.error("Failed to fetch questions from backend: HTTP status", response.status);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Backend not available. Falling back to local static questions data.', error);
|
console.error('Backend not available. Falling back to local static questions data.', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user