File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff 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 } ` ) ;
You can’t perform that action at this time.
0 commit comments