Skip to content

Commit 061e4bc

Browse files
fix(frontend): handle new API response format for /specs
1 parent 2711e8a commit 061e4bc

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

app/src/App.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,20 @@ function App() {
9898
const response = await fetch(`${API_URL}/specs`);
9999
if (!response.ok) throw new Error('Failed to fetch specs');
100100
const data = await response.json();
101-
setSpecs(data.specs);
101+
// API returns array of {id, title, ...} objects - extract IDs
102+
const specIds = Array.isArray(data) ? data.map((s: { id: string }) => s.id) : data.specs || [];
103+
setSpecs(specIds);
102104

103105
// Check URL for spec parameter
104106
const urlParams = new URLSearchParams(window.location.search);
105107
const specFromUrl = urlParams.get('spec');
106108

107-
if (specFromUrl && data.specs.includes(specFromUrl)) {
109+
if (specFromUrl && specIds.includes(specFromUrl)) {
108110
setSelectedSpec(specFromUrl);
109-
} else if (data.specs.length > 0) {
111+
} else if (specIds.length > 0) {
110112
// Select random spec
111-
const randomIndex = Math.floor(Math.random() * data.specs.length);
112-
setSelectedSpec(data.specs[randomIndex]);
113+
const randomIndex = Math.floor(Math.random() * specIds.length);
114+
setSelectedSpec(specIds[randomIndex]);
113115
}
114116
} catch (err) {
115117
setError(`Error loading specs: ${err}`);

0 commit comments

Comments
 (0)