@@ -17,6 +17,7 @@ import {
1717import { useRemoveTopic , useUpdateTopic } from "@/lib/tanstack/mutation/topic" ;
1818import { useGetCustomStickerById } from "@/lib/tanstack/query/custom-sticker" ;
1919import { useGetTopicById } from "@/lib/tanstack/query/topic" ;
20+ import { useTopicStore } from "@/lib/zustand/topic" ;
2021import { uploadImage } from "@/services/image" ;
2122import { containsMarkdown } from "@/utils/markdown" ;
2223import { revalidatePath } from "@/utils/revalidate" ;
@@ -33,8 +34,8 @@ import ToggleBlock from "./toggle-block";
3334import RemoveDialogContent from "../remove-dialog-content" ;
3435
3536interface BlockNoteProps {
36- topicId : string ;
37- stickerId : string ;
37+ topicId : string | null ;
38+ stickerId : string | null ;
3839}
3940
4041const blockNoteSchema = BlockNoteSchema . create ( {
@@ -58,6 +59,8 @@ export default function BlockNote({ topicId, stickerId }: BlockNoteProps) {
5859 const { data : customSticker , isLoading : isCustomStickerLoading } =
5960 useGetCustomStickerById ( stickerId ) ;
6061
62+ const topicStore = useTopicStore ( ) ;
63+
6164 const [ title , setTitle ] = useState ( topic ?. title || customSticker ?. title || "" ) ;
6265
6366 const editor = useCreateBlockNote ( {
@@ -86,6 +89,7 @@ export default function BlockNote({ topicId, stickerId }: BlockNoteProps) {
8689 isDeleteCustomStickerPending ;
8790
8891 const onSave = async ( ) => {
92+ if ( ! topicId ) return ;
8993 try {
9094 const content = editor . blocksToHTMLLossy ( ) ;
9195 if ( ! isCustomSticker ) {
@@ -98,67 +102,78 @@ export default function BlockNote({ topicId, stickerId }: BlockNoteProps) {
98102 {
99103 onSuccess : async ( ) => {
100104 successToast ( "토픽이 성공적으로 수정되었어요." ) ;
101- await invalidateMany ( [
102- [ TOPIC . GET_ALL_TOPICS ] ,
103- [ TOPIC . GET_TOPIC_BOARD_BY_ID , topicId ] ,
104- ] ) ;
105- router . back ( ) ;
106- } ,
107- }
108- ) ;
109- } else {
110- await updateCustomSticker (
111- {
112- customStickerId : stickerId ,
113- topicId,
114- title,
115- content,
116- } ,
117- {
118- onSuccess : async ( ) => {
119- successToast ( "스티커가 성공적으로 수정되었어요." ) ;
120- await invalidateMany ( [
121- [ TOPIC . GET_TOPIC_BOARD_BY_ID , topicId ] ,
122- [ CUSTOM_STICKER . GET_CUSTOM_STICKER_BY_ID , stickerId ] ,
123- ] ) ;
124- router . back ( ) ;
105+ invalidateQueries ( [ TOPIC . GET_ALL_TOPICS ] ) ;
106+ invalidateQueries ( [ TOPIC . GET_TOPIC_BY_ID , topicId , stickerId ] ) ;
107+ invalidateQueries ( [ TOPIC . GET_TOPIC_BOARD_BY_ID , topicId ] ) ;
108+
109+ if ( ! topicStore . isOpen ) {
110+ router . back ( ) ;
111+ }
112+ topicStore . reset ( ) ;
125113 } ,
126114 }
127115 ) ;
116+ return ;
128117 }
118+ if ( ! stickerId ) return ;
119+ await updateCustomSticker (
120+ {
121+ customStickerId : stickerId ,
122+ topicId,
123+ title,
124+ content,
125+ } ,
126+ {
127+ onSuccess : async ( ) => {
128+ successToast ( "스티커가 성공적으로 수정되었어요." ) ;
129+ invalidateQueries ( [ CUSTOM_STICKER . GET_CUSTOM_STICKER_BY_ID , stickerId ] ) ;
130+ invalidateQueries ( [ TOPIC . GET_TOPIC_BOARD_BY_ID , topicId ] ) ;
131+ if ( ! topicStore . isOpen ) {
132+ router . back ( ) ;
133+ }
134+ topicStore . reset ( ) ;
135+ } ,
136+ }
137+ ) ;
129138 } catch {
130139 errorToast ( "토픽 수정에 실패했어요." ) ;
131140 }
132141 } ;
133142
134143 const onDelete = async ( ) => {
135- if ( ! isCustomSticker ) {
144+ if ( ! isCustomSticker && topicId ) {
136145 await removeTopic ( topicId , {
137146 onSuccess : ( ) => {
138147 successToast ( "토픽이 성공적으로 삭제되었어요." ) ;
139148 invalidateQueries ( [ TOPIC . GET_ALL_TOPICS ] ) ;
140149 revalidatePath ( `/topic/${ topicId } ` ) ;
150+ revalidatePath ( `/topic/${ topicId } /sticker` ) ;
141151 router . push ( "/topic" ) ;
152+ topicStore . reset ( ) ;
142153 } ,
143154 onError : ( ) => {
144155 errorToast ( "토픽 삭제에 실패했어요." ) ;
145156 } ,
146157 } ) ;
147- } else {
148- await removeCustomSticker ( stickerId , {
149- onSuccess : ( ) => {
150- successToast ( "스티커가 성공적으로 삭제되었어요." ) ;
151- invalidateMany ( [
152- [ TOPIC . GET_TOPIC_BOARD_BY_ID , topicId ] ,
153- [ CUSTOM_STICKER . GET_CUSTOM_STICKER_BY_ID , stickerId ] ,
154- ] ) ;
155- router . back ( ) ;
156- } ,
157- onError : ( ) => {
158- errorToast ( "스티커 삭제에 실패했어요." ) ;
159- } ,
160- } ) ;
158+ return ;
161159 }
160+ if ( ! stickerId ) return ;
161+ await removeCustomSticker ( stickerId , {
162+ onSuccess : ( ) => {
163+ successToast ( "스티커가 성공적으로 삭제되었어요." ) ;
164+ invalidateMany ( [
165+ [ TOPIC . GET_TOPIC_BOARD_BY_ID , topicId ] ,
166+ [ CUSTOM_STICKER . GET_CUSTOM_STICKER_BY_ID , stickerId ] ,
167+ ] ) ;
168+ if ( ! topicStore . isOpen ) {
169+ router . back ( ) ;
170+ }
171+ topicStore . reset ( ) ;
172+ } ,
173+ onError : ( ) => {
174+ errorToast ( "스티커 삭제에 실패했어요." ) ;
175+ } ,
176+ } ) ;
162177 } ;
163178
164179 useEffect ( ( ) => {
@@ -197,14 +212,14 @@ export default function BlockNote({ topicId, stickerId }: BlockNoteProps) {
197212 < Loader2 size = { 24 } className = "animate-spin" />
198213 </ div >
199214 ) : (
200- < >
215+ < div className = "h-full space-y-2" >
201216 < input
202217 className = "border-border w-full border-b pb-3 text-3xl font-bold outline-none"
203218 placeholder = "제목을 입력해주세요"
204219 value = { title }
205220 onChange = { ( e ) => setTitle ( e . target . value ) }
206221 />
207- < BlockNoteView className = "h-[calc(100%-8rem )]" editor = { editor } />
222+ < BlockNoteView className = "h-[calc(100%-9.25rem )]" editor = { editor } />
208223 < div className = "flex gap-3" >
209224 < Button
210225 onClick = { onSave }
@@ -237,7 +252,7 @@ export default function BlockNote({ topicId, stickerId }: BlockNoteProps) {
237252 />
238253 </ Dialog >
239254 </ div >
240- </ >
255+ </ div >
241256 ) }
242257 </ div >
243258 ) ;
0 commit comments