1- " use client" ;
1+ ' use client' ;
22
33import React , { useEffect , useState } from 'react' ;
44import Publication from './Publication' ;
55
66interface PublicationData {
7- type : string ;
8- author : string [ ] ;
9- title : string ;
10- booktitle : string ;
11- year : number ;
12- address : string ;
13- url ?: string ;
14- publisher ?: string ;
15- pages ?: string ;
7+ type : string ;
8+ author : string [ ] ;
9+ title : string ;
10+ booktitle : string ;
11+ year : number ;
12+ address : string ;
13+ url ?: string ;
14+ publisher ?: string ;
15+ pages ?: string ;
1616}
1717
1818const PublicationList : React . FC = ( ) => {
19- const [ publications , setPublications ] = useState < PublicationData [ ] > ( [ ] ) ;
20-
21- useEffect ( ( ) => {
22- fetch ( '/publications.json' )
23- . then ( ( response ) => response . json ( ) )
24- . then ( ( data ) => setPublications ( data ) )
25- . catch ( ( error ) => console . error ( "Error loading publications data:" , error ) ) ;
26- } , [ ] ) ;
27-
28- return (
29- < div className = "px-4 pb-4" >
30- { publications . map ( ( pub , index ) => (
31- < Publication
32- key = { index }
33- title = { pub . title }
34- authors = { pub . author }
35- booktitle = { pub . booktitle }
36- year = { pub . year }
37- address = { pub . address }
38- url = { pub . url }
39- publisher = { pub . publisher }
40- pages = { pub . pages }
41- />
42- ) ) }
43- </ div >
44- ) ;
19+ const [ publications , setPublications ] = useState < PublicationData [ ] | null > (
20+ null
21+ ) ;
22+ const [ error , setError ] = useState < string | null > ( null ) ;
23+
24+ useEffect ( ( ) => {
25+ fetch ( '/publications.json' )
26+ . then ( ( res ) => {
27+ if ( ! res . ok ) throw new Error ( 'Failed to load publication data.' ) ;
28+ return res . json ( ) ;
29+ } )
30+ . then ( ( data ) => setPublications ( data ) )
31+ . catch ( ( err ) => {
32+ console . error ( 'Error loading publications data:' , err ) ;
33+ setError ( 'Could not load publications.' ) ;
34+ } ) ;
35+ } , [ ] ) ;
36+
37+ if ( error ) {
38+ return < p className = 'text-neutral-5 italic' > ⚠️ { error } </ p > ;
39+ }
40+
41+ if ( publications === null ) {
42+ return < p className = 'text-neutral-6 italic' > Loading publications...</ p > ;
43+ }
44+
45+ if ( publications . length === 0 ) {
46+ return < p className = 'text-neutral-6 italic' > No publications found.</ p > ;
47+ }
48+
49+ return (
50+ < div className = 'px-4 pb-4' >
51+ { publications . map ( ( pub , index ) => (
52+ < Publication
53+ key = { index }
54+ title = { pub . title }
55+ authors = { pub . author }
56+ booktitle = { pub . booktitle }
57+ year = { pub . year }
58+ address = { pub . address }
59+ url = { pub . url }
60+ publisher = { pub . publisher }
61+ pages = { pub . pages }
62+ />
63+ ) ) }
64+ </ div >
65+ ) ;
4566} ;
4667
47- export default PublicationList ;
68+ export default PublicationList ;
0 commit comments