File tree Expand file tree Collapse file tree 1 file changed +23
-4
lines changed
frontend/src/components/pages Expand file tree Collapse file tree 1 file changed +23
-4
lines changed Original file line number Diff line number Diff line change 1- import React from 'react' ;
1+ import React , { useEffect , useState } from 'react' ;
22import { useParams } from 'react-router-dom' ;
33
44export function Content ( ) {
5- const { courseID } = useParams ( ) ;
6- const { contentID } = useParams ( ) ;
5+ const { courseID } = useParams ( ) ;
6+ const { contentID } = useParams ( ) ;
7+ const [ courseInfo , setCourseInfo ] = useState ( null ) ;
8+ const [ error , setError ] = useState ( null ) ;
9+
10+ useEffect ( ( ) => {
11+ fetch ( `http://localhost:4000/course/${ courseID } ` )
12+ . then ( ( response ) => {
13+ if ( ! response . ok ) {
14+ throw new Error ( 'Network response was not ok' ) ;
15+ }
16+ return response . json ( ) ;
17+ } )
18+ . then ( ( data ) => setCourseInfo ( data . course ) )
19+ . catch ( ( error ) => setError ( error . message ) ) ;
20+ } , [ courseID ] ) ;
21+
22+ if ( error ) return < p > Error: { error } </ p > ;
23+ if ( ! courseInfo ) return < p > Loading...</ p > ;
724
825 return (
926 < div className = "p-6" >
10- < h1 className = "text-2xl font-bold mb-4" > Course Name</ h1 >
27+ < a href = { `/courses/${ courseID } ` } >
28+ < span className = "text-2xl font-bold mb-4 hover:underline " > { courseInfo . title } </ span >
29+ </ a >
1130 < div className = "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6" >
1231 Course id: { courseID }
1332 </ div >
You can’t perform that action at this time.
0 commit comments