1+ import { useParams } from 'react-router' ;
2+ import useMediaQueries from '@/hooks/useMediaQueries' ;
3+ import { getTrackName } from './ProjectItem' ;
4+ import * as S from './ProjectDetail.styles' ;
5+ import { useEffect , useState } from 'react' ;
6+ import { DetailedProjectResponse } from '@/models/project' ;
7+ import { getProjectById } from '@/services/project' ;
8+ import DetailLayout from '@/layouts/DetailLayout/DetailLayout' ;
9+ import Logger from '@/utils/Logger' ;
10+
11+ const ProjectDetail : React . FC = ( ) => {
12+ const { projectId } = useParams < { projectId : string } > ( ) ;
13+ const { isMobile, isTablet, isDesktop } = useMediaQueries ( ) ;
14+ const [ project , setProject ] = useState < DetailedProjectResponse | null > ( null ) ;
15+ const [ loading , setLoading ] = useState ( true ) ;
16+ const [ error , setError ] = useState < Error | null > ( null ) ;
17+
18+ useEffect ( ( ) => {
19+ const fetchProject = async ( ) => {
20+ try {
21+ if ( ! projectId ) return ;
22+ const response = await getProjectById ( parseInt ( projectId ) ) ;
23+ console . log ( 'Fetched Project Data:' , response ) ;
24+
25+ if ( response . data ) {
26+ const projectData = response . data ;
27+ setProject ( projectData ) ;
28+ }
29+ } catch ( err ) {
30+ console . error ( 'Error fetching project:' , err ) ;
31+ setError ( err instanceof Error ? err : new Error ( '프로젝트를 불러오는데 실패했습니다.' ) ) ;
32+ Logger . error ( err ) ;
33+ } finally {
34+ setLoading ( false ) ;
35+ }
36+ } ;
37+
38+ fetchProject ( ) ;
39+ } , [ projectId ] ) ;
40+
41+ if ( loading ) {
42+ return (
43+ < S . Container $isMobile = { isMobile } $isTablet = { isTablet } $isDesktop = { isDesktop } >
44+ 로딩 중...
45+ </ S . Container >
46+ ) ;
47+ }
48+
49+ if ( error || ! project ) {
50+ return (
51+ < S . Container $isMobile = { isMobile } $isTablet = { isTablet } $isDesktop = { isDesktop } >
52+ 에러가 발생했습니다: { error ?. message }
53+ </ S . Container >
54+ ) ;
55+ }
56+
57+ return (
58+ < S . Container $isMobile = { isMobile } $isTablet = { isTablet } $isDesktop = { isDesktop } >
59+ < S . ProjectPageTitle $isMobile = { isMobile } $isTablet = { isTablet } $isDesktop = { isDesktop } >
60+ 프로젝트
61+ </ S . ProjectPageTitle >
62+ < DetailLayout
63+ title = { project . title }
64+ content = { `${ project . introduction } \n\n${ project . content } ` }
65+ tag = { getTrackName ( project . track ) }
66+ thumbnailUrl = { project . thumbnailImageUrl }
67+ imageUrls = { project . bodyImageUrl ? [ project . bodyImageUrl ] : [ ] }
68+ date = { project . githubLink }
69+ />
70+ </ S . Container >
71+ ) ;
72+ } ;
73+
74+ export default ProjectDetail ;
0 commit comments