1+ // "use client"
2+
3+ // import { useEffect, useState } from "react"
4+ // import { Card } from "@/components/ui/card"
5+ // import { Button } from "@/components/ui/Button"
6+ // import { Switch } from "@/components/ui/switch"
7+ // import { ShareButton } from "@/components/analysis/ShareButton"
8+ // import { Globe, Lock, MessageSquare } from "lucide-react"
9+ // import { useRepositoryPublic } from "@/hooks/analysis/useRepositoryPublic"
10+ // import { CommentSection } from "@/components/community/CommentSection"
11+ // import { analysisApi } from "@/lib/api/analysis"
12+ // import type { HistoryResponseDto } from "@/types/analysis"
13+
14+ // interface Props {
15+ // userId: number
16+ // repoId: number
17+ // initialPublic: boolean
18+ // }
19+
20+ // export function RepositoryPublicSection({ userId, repoId, initialPublic }: Props) {
21+ // const { isPublic, togglePublic } = useRepositoryPublic(initialPublic, userId, repoId)
22+
23+ // const [analysisResultId, setAnalysisResultId] = useState<number | null>(null)
24+ // const [loading, setLoading] = useState(true)
25+
26+ // useEffect(() => {
27+ // const loadAnalysisId = async () => {
28+ // try {
29+ // const historyResponse: HistoryResponseDto = await analysisApi.getRepositoryHistory(userId, repoId)
30+ // // ✅ 최신 분석 결과 ID 추출
31+ // if (historyResponse.analysisVersions && historyResponse.analysisVersions.length > 0) {
32+ // const latest = historyResponse.analysisVersions[0]
33+ // setAnalysisResultId(latest.analysisId)
34+ // } else {
35+ // console.warn("이 리포지토리에 분석 기록이 없습니다.")
36+ // }
37+ // } catch (err) {
38+ // console.error("❌ 분석 히스토리 조회 실패:", err)
39+ // } finally {
40+ // setLoading(false)
41+ // }
42+ // }
43+
44+ // loadAnalysisId()
45+ // }, [userId, repoId])
46+
47+ // return (
48+ // <>
49+ // {/* 🌐 공개 설정 */}
50+ // <Card className="mb-8 p-6">
51+ // <div className="flex items-center justify-between">
52+ // <div className="flex items-center gap-3">
53+ // {isPublic ? (
54+ // <Globe className="h-5 w-5 text-green-500" />
55+ // ) : (
56+ // <Lock className="h-5 w-5 text-muted-foreground" />
57+ // )}
58+ // <div>
59+ // <h3 className="font-semibold">리포지토리 공개 설정</h3>
60+ // <p className="text-sm text-muted-foreground">
61+ // {isPublic
62+ // ? "이 리포지토리의 분석 결과가 커뮤니티에 공개됩니다."
63+ // : "이 리포지토리의 분석 결과는 비공개 상태입니다." }
64+ // </p>
65+ // </div>
66+ // </div>
67+
68+ // <div className="flex items-center gap-2">
69+ // <span className="text-sm text-muted-foreground">{isPublic ? "공개" : "비공개"}</span>
70+ // <Switch checked={isPublic} onCheckedChange={togglePublic} />
71+ // </div>
72+ // </div>
73+ // </Card>
74+
75+ // {/* 💬 커뮤니티 섹션 */}
76+ // {isPublic ? (
77+ // <>
78+ // <Card className="p-6 mb-8">
79+ // <div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
80+ // <div>
81+ // <h3 className="mb-1 font-semibold">커뮤니티 반응</h3>
82+ // <p className="text-sm text-muted-foreground">다른 개발자들과 소통하세요.</p>
83+ // </div>
84+ // <div className="flex gap-2">
85+ // <Button variant="outline" size="sm" className="gap-2 bg-transparent">
86+ // <MessageSquare className="h-4 w-4" />
87+ // 댓글 (n)
88+ // </Button>
89+ // <ShareButton />
90+ // </div>
91+ // </div>
92+ // </Card>
93+
94+ // {/* ✅ analysisResultId가 있을 때만 CommentSection 표시 */}
95+ // {loading ? (
96+ // <p className="text-muted-foreground text-sm">분석 데이터를 불러오는 중...</p>
97+ // ) : analysisResultId ? (
98+ // <CommentSection analysisResultId={analysisResultId} memberId={userId} />
99+ // ) : (
100+ // <p className="text-muted-foreground text-sm">아직 분석 기록이 없습니다.</p>
101+ // )}
102+ // </>
103+ // ) : (
104+ // <Card className="p-6 text-center text-muted-foreground">
105+ // 🔒 이 리포지토리는 현재 비공개 상태입니다.
106+ // </Card>
107+ // )}
108+ // </>
109+ // )
110+ // }
111+
1112"use client"
2113
114+ import { useEffect , useState } from "react"
3115import { Card } from "@/components/ui/card"
4- import { Button } from "@/components/ui/Button"
116+ import { Button } from "@/components/ui/button" // ✅ 대소문자 수정
5117import { Switch } from "@/components/ui/switch"
6118import { ShareButton } from "@/components/analysis/ShareButton"
7- import { Globe , Lock , MessageSquare , Share2 , ThumbsUp } from "lucide-react"
119+ import { Globe , Lock , MessageSquare } from "lucide-react"
8120import { useRepositoryPublic } from "@/hooks/analysis/useRepositoryPublic"
9- import { useState } from "react"
121+ import { CommentSection } from "@/components/community/CommentSection"
122+ import { analysisApi } from "@/lib/api/analysis"
123+ import type { HistoryResponseDto } from "@/types/analysis"
10124
11125interface Props {
12126 userId : number
@@ -16,13 +130,30 @@ interface Props {
16130
17131export function RepositoryPublicSection ( { userId, repoId, initialPublic } : Props ) {
18132 const { isPublic, togglePublic } = useRepositoryPublic ( initialPublic , userId , repoId )
19- const [ liked , setLiked ] = useState ( false )
20- const [ likeCount , setLikeCount ] = useState ( 42 )
21133
22- const handleLike = ( ) => {
23- setLiked ( ( prev ) => ! prev )
24- setLikeCount ( ( prev ) => ( liked ? prev - 1 : prev + 1 ) )
25- }
134+ const [ analysisResultId , setAnalysisResultId ] = useState < number | null > ( null )
135+ const [ loading , setLoading ] = useState ( true )
136+
137+ useEffect ( ( ) => {
138+ const loadAnalysisId = async ( ) => {
139+ try {
140+ const historyResponse : HistoryResponseDto = await analysisApi . getRepositoryHistory ( userId , repoId )
141+ // ✅ 최신 분석 결과 ID 추출
142+ if ( Array . isArray ( historyResponse . analysisVersions ) && historyResponse . analysisVersions . length > 0 ) {
143+ const latest = historyResponse . analysisVersions [ 0 ]
144+ setAnalysisResultId ( latest . analysisId )
145+ } else {
146+ console . warn ( "이 리포지토리에 분석 기록이 없습니다." )
147+ }
148+ } catch ( err ) {
149+ console . error ( "❌ 분석 히스토리 조회 실패:" , err )
150+ } finally {
151+ setLoading ( false )
152+ }
153+ }
154+
155+ loadAnalysisId ( )
156+ } , [ userId , repoId ] )
26157
27158 return (
28159 < >
@@ -56,28 +187,40 @@ export function RepositoryPublicSection({ userId, repoId, initialPublic }: Props
56187 { isPublic ? (
57188 < >
58189 < Card className = "p-6 mb-8" >
59- < div className = "flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between" >
190+ { /* 헤더 영역 */ }
191+ < div className = "flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between mb-4" >
60192 < div >
61193 < h3 className = "mb-1 font-semibold" > 커뮤니티 반응</ h3 >
62194 < p className = "text-sm text-muted-foreground" > 다른 개발자들과 소통하세요.</ p >
63195 </ div >
64- < div className = "flex gap-2" >
196+ { /* <div className="flex gap-2">
65197 <Button variant="outline" size="sm" className="gap-2 bg-transparent">
66198 <MessageSquare className="h-4 w-4" />
67199 댓글 (n)
68200 </Button>
69201 <ShareButton />
70- </ div >
202+ </div>*/ }
71203 </ div >
72- </ Card >
73204
74- { /* ⚠️ TODO: 댓글 컴포넌트 연결 위치 */ }
75- { /*
76- <CommentSection
77- repoId={repoId}
78- userId={userId}
79- />
80- */ }
205+ { /* 본문 영역: 댓글 작성 → 댓글 목록 */ }
206+ { loading ? (
207+ < p className = "flex flex-col gap-6" > 분석 데이터를 불러오는 중...</ p >
208+ ) : analysisResultId ? (
209+ < div className = "text-muted-foreground text-sm" >
210+ { /* ✏️ 댓글 작성 폼 */ }
211+ < CommentSection analysisResultId = { analysisResultId } memberId = { userId } />
212+
213+ { /* 💬 댓글 목록 */ }
214+ < div className = "border-t pt-6" >
215+ { /* 댓글 목록이 CommentSection 안에서 렌더링되거나 별도 CommentList가 있다면 여기에 배치 */ }
216+ { /* 예: <CommentList analysisResultId={analysisResultId} /> */ }
217+ { /* CommentSection이 이미 작성+조회 포함한다면 그대로 둬도 됨 */ }
218+ </ div >
219+ </ div >
220+ ) : (
221+ < p className = "text-muted-foreground text-sm" > 아직 분석 기록이 없습니다.</ p >
222+ ) }
223+ </ Card >
81224 </ >
82225 ) : (
83226 < Card className = "p-6 text-center text-muted-foreground" >
0 commit comments