@@ -4,15 +4,15 @@ import AISummary from "@/assets/ai-summary.svg?react";
44import Logo from "@/assets/logo.svg?react" ;
55import CardWrapper from "@/components/create-bookmark/card-wrapper" ;
66import Loading from "@/components/loading" ;
7+ import { useReplaceNavigate } from "@/hooks/use-replace-navigate" ;
78import { useCreateCategory } from "@/state/mutation/category" ;
89import { useCompleteCreateStar , useUpdateStar } from "@/state/mutation/star" ;
910import { useGetKeywords } from "@/state/query/keyword" ;
1011import { useGetStarById } from "@/state/query/star" ;
1112import { useStarStore } from "@/state/zustand/star" ;
12- import { useTabStore } from "@/state/zustand/tab" ;
1313import { CategoryListProps } from "@/types/category" ;
1414import { CompleteSummarizeStarProps } from "@/types/star" ;
15- import { Graph2D } from "@repo/ui" ;
15+ import { cn , Graph2D } from "@repo/ui" ;
1616import { Keyword , RectangleButton , Spinner , Textarea } from "@repo/ui" ;
1717
1818import { Navigate , useLocation , useSearchParams } from "react-router-dom" ;
@@ -41,9 +41,10 @@ const CreateBookmark = () => {
4141 const [ searchParams ] = useSearchParams ( ) ;
4242 const id = searchParams . get ( "id" ) ;
4343
44+ // 추후 AI 요약 기능 추가 시 tanstack query의 isPending 사용
45+ const [ isAISummaryPending , setIsAISummaryPending ] = useState ( false ) ;
4446 const [ bookmark , setBookmark ] = useState < StateProps > ( Object . assign ( DEFAULT_BOOKMARK , state ) ) ;
4547 const stars = useStarStore ( ( state ) => state . stars ) ;
46- const setIsFindingExistPath = useTabStore ( ( state ) => state . setIsFindingExistPath ) ;
4748
4849 const { mutateAsync : mutateAsyncCompleteCreateStar } = useCompleteCreateStar ( ) ;
4950 const { mutateAsync : mutateAsyncUpdateStar } = useUpdateStar ( ) ;
@@ -52,6 +53,8 @@ const CreateBookmark = () => {
5253 const { data : keywords } = useGetKeywords ( ) ;
5354 const { data : star , isLoading : isLoadingGetStar } = useGetStarById ( id ) ;
5455
56+ const navigate = useReplaceNavigate ( ) ;
57+
5558 useEffect ( ( ) => {
5659 if ( ! isLoadingGetStar && star ?. result ) {
5760 setBookmark ( ( prev ) => ( {
@@ -77,13 +80,31 @@ const CreateBookmark = () => {
7780 // 관련된 노드만 필터링
7881 const relatedNodes = stars . starListDto . filter ( ( star ) => relatedNodeIds . has ( star . starId ) ) ;
7982
83+ // 현재 북마크 정보 가져오기
84+ const currentStar = stars . starListDto . find ( ( star ) => star . starId === id ) ;
85+
86+ // 연관된 노드가 없으면 현재 북마크만 포함
87+ const nodes =
88+ relatedNodes . length > 0
89+ ? relatedNodes . map ( ( star ) => ( {
90+ id : star . starId ,
91+ name : star . title ,
92+ val : Math . min ( star . views , 10 ) ,
93+ url : star . siteUrl ,
94+ } ) )
95+ : currentStar
96+ ? [
97+ {
98+ id : currentStar . starId ,
99+ name : currentStar . title ,
100+ val : 10 ,
101+ url : currentStar . siteUrl ,
102+ } ,
103+ ]
104+ : [ ] ;
105+
80106 return {
81- nodes : relatedNodes . map ( ( star ) => ( {
82- id : star . starId ,
83- name : star . title ,
84- val : Math . min ( star . views , 10 ) ,
85- url : star . siteUrl ,
86- } ) ) ,
107+ nodes,
87108 links : relatedLinks . map ( ( link ) => ( {
88109 source : link . linkedNodeIdList [ 0 ] ,
89110 target : link . linkedNodeIdList [ 1 ] ,
@@ -100,8 +121,6 @@ const CreateBookmark = () => {
100121 return < Navigate to = "/bad-request" replace /> ;
101122 }
102123
103- const saveDisabled = bookmark . categoryName . trim ( ) === "" ;
104-
105124 const onSelectCategory = ( category : string ) => {
106125 setBookmark ( ( prev ) => ( { ...prev , categoryName : category } ) ) ;
107126 } ;
@@ -144,38 +163,22 @@ const CreateBookmark = () => {
144163 } ;
145164
146165 const onClickSave = async ( ) => {
147- // id가 있으면 수정하기 API 요청
148- const categoryName = bookmark . categories . find (
149- ( category ) => category . name === bookmark . categoryName
150- ) ?. name ;
151-
152- if ( ! categoryName ) {
153- return ;
154- }
155-
156166 const body = {
157167 ...bookmark ,
158168 keywordList : bookmark . keywords ,
159169 } ;
160170
161171 if ( id ) {
162- await mutateAsyncUpdateStar (
163- { id, body } ,
164- {
165- onSuccess : ( ) => {
166- setIsFindingExistPath ( true ) ;
167- } ,
168- }
169- ) ;
172+ await mutateAsyncUpdateStar ( { id, body } ) ;
170173 } else {
171- await mutateAsyncCompleteCreateStar ( body , {
172- onSuccess : ( ) => {
173- setIsFindingExistPath ( true ) ;
174- } ,
175- } ) ;
174+ await mutateAsyncCompleteCreateStar ( body ) ;
176175 }
177176 } ;
178177
178+ const onClickCancel = ( ) => {
179+ navigate ( "/bookmark" ) ;
180+ } ;
181+
179182 if ( isLoadingGetStar ) {
180183 return (
181184 < div className = "flex h-full flex-col items-center justify-center gap-10 text-notification" >
@@ -188,15 +191,9 @@ const CreateBookmark = () => {
188191 return (
189192 < Loading title = "북마크를 저장하고 있어요!" >
190193 < main className = "flex h-full flex-col gap-6" >
191- < header className = "flex items-center justify-between" >
192- < div className = "flex items-center gap-1" >
193- < Logo />
194- < p className = "text-description font-bold" > Nebula</ p >
195- </ div >
196- < button className = "flex items-center gap-1" >
197- < AISummary />
198- < p className = "text-xs font-semibold" > Nebula AI</ p >
199- </ button >
194+ < header className = "flex items-center gap-1" >
195+ < Logo />
196+ < p className = "text-description font-bold" > Nebula</ p >
200197 </ header >
201198 { id && (
202199 < section >
@@ -220,6 +217,17 @@ const CreateBookmark = () => {
220217 value = { bookmark . summaryAI }
221218 onChange = { onChangeText }
222219 placeholder = "북마크에 대한 요약을 작성할 수 있어요."
220+ rightElement = {
221+ < button
222+ className = { cn ( "flex items-center gap-1" , isAISummaryPending && "animate-pulse" ) }
223+ onClick = { ( ) => setIsAISummaryPending ( true ) }
224+ >
225+ < AISummary />
226+ < p className = "text-xs font-semibold" >
227+ { isAISummaryPending ? "요약 중..." : "인공지능 요약" }
228+ </ p >
229+ </ button >
230+ }
223231 />
224232 < Textarea
225233 id = "userMemo"
@@ -239,11 +247,11 @@ const CreateBookmark = () => {
239247 onUpdateKeyword = { onUpdateKeyword }
240248 />
241249 </ section >
242- < section className = "flex gap-3" >
243- < RectangleButton variation = "outline" > 취소</ RectangleButton >
244- < RectangleButton disabled = { saveDisabled } onClick = { onClickSave } >
245- 저장
250+ < section className = "flex gap-3 pb-5" >
251+ < RectangleButton variation = "outline" onClick = { onClickCancel } >
252+ 취소
246253 </ RectangleButton >
254+ < RectangleButton onClick = { onClickSave } > 저장</ RectangleButton >
247255 </ section >
248256 </ main >
249257 </ Loading >
0 commit comments