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-
1121"use client"
1132
1143import { useEffect , useState } from "react"
1154import { Card } from "@/components/ui/card"
116- import { Button } from "@/components/ui/button " // ✅ 대소문자 수정
5+ import { Button } from "@/components/ui/Button " // ✅ 대소문자 수정
1176import { Switch } from "@/components/ui/switch"
1187import { ShareButton } from "@/components/analysis/ShareButton"
1198import { Globe , Lock , MessageSquare } from "lucide-react"
@@ -133,8 +22,23 @@ export function RepositoryPublicSection({ userId, repoId, initialPublic }: Props
13322
13423 const [ analysisResultId , setAnalysisResultId ] = useState < number | null > ( null )
13524 const [ loading , setLoading ] = useState ( true )
25+ const [ currentUserId , setCurrentUserId ] = useState < number | null > ( null )
13626
13727 useEffect ( ( ) => {
28+ const stored = localStorage . getItem ( "user" )
29+ if ( stored ) {
30+ try {
31+ const parsed = JSON . parse ( stored )
32+ setCurrentUserId ( Number ( parsed . id ) )
33+ } catch ( err ) {
34+ console . error ( "유저 정보 파싱 실패:" , err )
35+ }
36+ }
37+ } , [ ] )
38+
39+ useEffect ( ( ) => {
40+ if ( ! userId || ! repoId ) return
41+
13842 const loadAnalysisId = async ( ) => {
13943 try {
14044 const historyResponse : HistoryResponseDto = await analysisApi . getRepositoryHistory ( userId , repoId )
@@ -155,9 +59,14 @@ export function RepositoryPublicSection({ userId, repoId, initialPublic }: Props
15559 loadAnalysisId ( )
15660 } , [ userId , repoId ] )
15761
62+ if ( currentUserId === null ) {
63+ return < div className = "p-6 text-center text-muted-foreground" > 사용자 정보를 불러오는 중...</ div >
64+ }
65+
15866 return (
15967 < >
16068 { /* 🌐 공개 설정 */ }
69+ { currentUserId === userId && (
16170 < Card className = "mb-8 p-6" >
16271 < div className = "flex items-center justify-between" >
16372 < div className = "flex items-center gap-3" >
@@ -182,6 +91,7 @@ export function RepositoryPublicSection({ userId, repoId, initialPublic }: Props
18291 </ div >
18392 </ div >
18493 </ Card >
94+ ) }
18595
18696 { /* 💬 커뮤니티 섹션 */ }
18797 { isPublic ? (
@@ -193,13 +103,13 @@ export function RepositoryPublicSection({ userId, repoId, initialPublic }: Props
193103 < h3 className = "mb-1 font-semibold" > 커뮤니티 반응</ h3 >
194104 < p className = "text-sm text-muted-foreground" > 다른 개발자들과 소통하세요.</ p >
195105 </ div >
196- { /* <div className="flex gap-2">
106+ < div className = "flex gap-2" >
197107 < Button variant = "outline" size = "sm" className = "gap-2 bg-transparent" >
198108 < MessageSquare className = "h-4 w-4" />
199109 댓글 (n)
200110 </ Button >
201111 < ShareButton />
202- </div>*/ }
112+ </ div >
203113 </ div >
204114
205115 { /* 본문 영역: 댓글 작성 → 댓글 목록 */ }
0 commit comments