@@ -9,46 +9,63 @@ import { useRouter } from "next/navigation";
9
9
import { toast } from "react-toastify" ;
10
10
import {
11
11
createPostComment ,
12
+ createRecomment ,
12
13
deletePostComment ,
14
+ deleteRecomment ,
13
15
updateCommentLike ,
14
16
updatePostComment ,
15
17
updatePostLike ,
18
+ updateRecomment ,
19
+ updateRecommentLike ,
16
20
} from "./api.service" ;
17
21
18
- export const useDeletePostMutation = ( ) => {
22
+ interface IUsePostCommentMutationProps {
23
+ id : number ;
24
+ detail : string ;
25
+ }
26
+
27
+ // like
28
+
29
+ export const useUpdatePostLikeMutation = ( ) => {
19
30
const apolloClient = useApolloClient ( ) ;
20
- const router = useRouter ( ) ;
21
31
22
- const mutations = useApolloMutation ( DELETE_POST , {
23
- onCompleted : ( ) => {
32
+ return useMutation ( ( id : string ) => updatePostLike ( id ) , {
33
+ onSuccess : ( ) => {
24
34
apolloClient . cache . reset ( ) ;
25
- toast . success ( "글이 삭제되었습니다!" ) ;
26
- router . push ( ROUTER . POST . LIST ) ;
27
35
} ,
28
36
} ) ;
29
- return mutations ;
30
37
} ;
31
38
32
- interface IUseCreateCommentMutationProps {
33
- id : string ;
34
- detail : string ;
35
- }
39
+ export const useUpdateCommentLikeMutation = ( ) => {
40
+ return useMutation ( ( id : number ) => updateCommentLike ( id ) ) ;
41
+ } ;
36
42
37
- export const useUpdatePostLikeMutation = ( ) => {
43
+ export const useUpdateRecommentLikeMutation = ( ) => {
44
+ return useMutation ( ( id : number ) => updateRecommentLike ( id ) ) ;
45
+ } ;
46
+
47
+ // post
48
+ export const useDeletePostMutation = ( ) => {
38
49
const apolloClient = useApolloClient ( ) ;
50
+ const router = useRouter ( ) ;
39
51
40
- return useMutation ( ( id : string ) => updatePostLike ( id ) , {
41
- onSuccess : ( ) => {
52
+ const mutations = useApolloMutation ( DELETE_POST , {
53
+ onCompleted : ( ) => {
42
54
apolloClient . cache . reset ( ) ;
55
+ toast . success ( "글이 삭제되었습니다!" ) ;
56
+ router . push ( ROUTER . POST . LIST ) ;
43
57
} ,
44
58
} ) ;
59
+ return mutations ;
45
60
} ;
46
61
62
+ // comment
63
+
47
64
export const useCreatePostCommentMutation = ( ) => {
48
65
const queryClient = useQueryClient ( ) ;
49
66
50
67
return useMutation (
51
- ( props : IUseCreateCommentMutationProps ) => createPostComment ( props ) ,
68
+ ( comment : IUsePostCommentMutationProps ) => createPostComment ( comment ) ,
52
69
{
53
70
onSuccess : ( ) => {
54
71
toast . success ( "댓글을 작성했어요!" ) ;
@@ -58,16 +75,11 @@ export const useCreatePostCommentMutation = () => {
58
75
) ;
59
76
} ;
60
77
61
- interface IUseUpdatePostCommentMutationProps {
62
- id : number ;
63
- detail : string ;
64
- }
65
-
66
78
export const useUpdatePostCommentMutation = ( ) => {
67
79
const queryClient = useQueryClient ( ) ;
68
80
69
81
return useMutation (
70
- ( comment : IUseUpdatePostCommentMutationProps ) => updatePostComment ( comment ) ,
82
+ ( comment : IUsePostCommentMutationProps ) => updatePostComment ( comment ) ,
71
83
{
72
84
onSuccess : ( ) => {
73
85
toast . success ( "댓글이 수정되었어요!" ) ;
@@ -88,6 +100,44 @@ export const useDeletePostCommentMutation = () => {
88
100
} ) ;
89
101
} ;
90
102
91
- export const useUpdateCommentLikeMutation = ( ) => {
92
- return useMutation ( ( id : number ) => updateCommentLike ( id ) ) ;
103
+ // recomment
104
+
105
+ export const useCreateRecommentMutation = ( ) => {
106
+ const queryClient = useQueryClient ( ) ;
107
+
108
+ return useMutation (
109
+ ( comment : IUsePostCommentMutationProps ) => createRecomment ( comment ) ,
110
+ {
111
+ onSuccess : ( ) => {
112
+ toast . success ( "답글을 작성했어요!" ) ;
113
+ queryClient . invalidateQueries ( [ KEY . RECOMMENT ] ) ;
114
+ queryClient . invalidateQueries ( [ KEY . COMMENT ] ) ;
115
+ } ,
116
+ } ,
117
+ ) ;
118
+ } ;
119
+
120
+ export const useUpdateRecommentMutation = ( ) => {
121
+ const queryClient = useQueryClient ( ) ;
122
+
123
+ return useMutation (
124
+ ( comment : IUsePostCommentMutationProps ) => updateRecomment ( comment ) ,
125
+ {
126
+ onSuccess : ( ) => {
127
+ toast . success ( "답글이 수정되었어요!" ) ;
128
+ queryClient . invalidateQueries ( [ KEY . RECOMMENT ] ) ;
129
+ } ,
130
+ } ,
131
+ ) ;
132
+ } ;
133
+
134
+ export const useDeleteRecommentMutation = ( ) => {
135
+ const queryClient = useQueryClient ( ) ;
136
+
137
+ return useMutation ( ( id : number ) => deleteRecomment ( id ) , {
138
+ onSuccess : ( ) => {
139
+ toast . success ( "답글이 삭제되었어요." ) ;
140
+ queryClient . invalidateQueries ( [ KEY . RECOMMENT ] ) ;
141
+ } ,
142
+ } ) ;
93
143
} ;
0 commit comments