1- import { useEffect , useState } from "react" ;
1+ import { useEffect , useMemo , useState } from "react" ;
22import Image from "next/image" ;
33import Link from "next/link" ;
44
@@ -11,7 +11,8 @@ import trash from "@/assets/icons/trash.svg";
1111import { useCreateCategory } from "@/lib/tanstack/mutation/category" ;
1212import { useDeleteStar , useUpdateStar } from "@/lib/tanstack/mutation/star" ;
1313import { useGetGraphDetail } from "@/lib/tanstack/query/graph" ;
14- import { Card , cn , Keyword , Modal , RectangleButton , Spinner , Textarea } from "@repo/ui" ;
14+ import { useBookmarkStore } from "@/lib/zustand/bookmark" ;
15+ import { Card , cn , Graph2D , Keyword , Modal , RectangleButton , Spinner , Textarea } from "@repo/ui" ;
1516
1617interface GraphDetailProps {
1718 open : boolean ;
@@ -29,11 +30,41 @@ const GraphDetail = ({ open, id, onClose }: GraphDetailProps) => {
2930 useGetGraphDetail ( id ) ;
3031
3132 const [ edit , setEdit ] = useState ( { activated : false , keyword : "" , ...( starData ?. result || { } ) } ) ;
33+ const stars = useBookmarkStore ( ( state ) => state . stars ) ;
3234
3335 const { mutateAsync : createCategory , isPending : createCategoryLoading } = useCreateCategory ( ) ;
3436 const { mutateAsync : updateStar , isPending : updateStarLoading } = useUpdateStar ( ) ;
3537 const { mutateAsync : deleteStar , isPending : deleteStarLoading } = useDeleteStar ( onClose ) ;
3638
39+ const graphData = useMemo ( ( ) => {
40+ if ( ! stars ?. starListDto || ! stars ?. linkListDto || ! id ) return { nodes : [ ] , links : [ ] } ;
41+
42+ // 현재 북마크와 연결된 링크만 필터링
43+ const relatedLinks = stars . linkListDto . filter ( ( link ) => link . linkedNodeIdList . includes ( id ) ) ;
44+
45+ // 관련된 노드 ID 수집
46+ const relatedNodeIds = new Set < string > ( ) ;
47+ relatedLinks . forEach ( ( link ) => {
48+ link . linkedNodeIdList . forEach ( ( nodeId ) => relatedNodeIds . add ( nodeId ) ) ;
49+ } ) ;
50+
51+ // 관련된 노드만 필터링
52+ const relatedNodes = stars . starListDto . filter ( ( star ) => relatedNodeIds . has ( star . starId ) ) ;
53+
54+ return {
55+ nodes : relatedNodes . map ( ( star ) => ( {
56+ id : star . starId ,
57+ name : star . title ,
58+ val : Math . min ( star . views , 10 ) ,
59+ url : star . siteUrl ,
60+ } ) ) ,
61+ links : relatedLinks . map ( ( link ) => ( {
62+ source : link . linkedNodeIdList [ 0 ] ,
63+ target : link . linkedNodeIdList [ 1 ] ,
64+ } ) ) ,
65+ } ;
66+ } , [ stars , id ] ) ;
67+
3768 const onSelectCategory = ( categoryName : string ) => {
3869 setEdit ( ( prev ) => ( { ...prev , categoryName } ) ) ;
3970 } ;
@@ -235,6 +266,19 @@ const GraphDetail = ({ open, id, onClose }: GraphDetailProps) => {
235266 ) }
236267 </ div >
237268 </ div >
269+ < Graph2D
270+ graphData = { {
271+ nodes : graphData . nodes . map ( ( star ) => ( {
272+ id : star . id ,
273+ name : star . name ,
274+ val : 1 ,
275+ } ) ) ,
276+ links : graphData . links . map ( ( link ) => ( {
277+ source : link . source ,
278+ target : link . target ,
279+ } ) ) ,
280+ } }
281+ />
238282 < Card
239283 Thumbnail = {
240284 starData ?. result ?. thumbnailUrl ? (
@@ -327,7 +371,9 @@ const GraphDetail = ({ open, id, onClose }: GraphDetailProps) => {
327371 ) : (
328372 < div className = "flex h-full w-full flex-col items-center justify-center gap-4 px-2" >
329373 < p > 북마크를 찾을 수 없습니다.</ p >
330- < RectangleButton onClick = { onCloseDetail } > 상세 창 닫기</ RectangleButton >
374+ < RectangleButton onClick = { onCloseDetail } className = "w-full flex-none" >
375+ 상세 창 닫기
376+ </ RectangleButton >
331377 </ div >
332378 ) }
333379 </ div >
0 commit comments