()
| 33 | }; |
| 34 | |
| 35 | export function useDeleteComment(): UseDeleteCommentRet { |
| 36 | const client = useQueryClient(); |
| 37 | const { showPrompt } = usePrompt(); |
| 38 | const { logEvent } = useLogContext(); |
| 39 | const { displayToast } = useToastNotification(); |
| 40 | const { requestMethod } = useRequestProtocol(); |
| 41 | |
| 42 | return { |
| 43 | deleteComment: useCallback( |
| 44 | async (commentId, parentId, post) => { |
| 45 | if (!(await showPrompt(options))) { |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | logEvent(postLogEvent(LogEvent.DeleteComment, post)); |
| 50 | await deleteComment(commentId, requestMethod); |
| 51 | displayToast('The comment has been deleted'); |
| 52 | // Callers pass `null` for root comments; `removePostComments` treats |
| 53 | // `parentId === commentId` as the root case, matching the convention |
| 54 | // used in MainComment (`parentId={comment.id}`). |
| 55 | removePostComments(client, post, commentId, parentId ?? commentId); |
| 56 | }, |
| 57 | [client, showPrompt, logEvent, displayToast, requestMethod], |
| 58 | ), |
| 59 | }; |
| 60 | } |
no test coverage detected