1- import React , { useState , useCallback } from 'react' ;
1+ import React , { useState , useCallback , useEffect } from 'react' ;
22import PropTypes from 'prop-types' ;
33import { useSelector , useDispatch } from 'react-redux' ;
4- import { Card , Popover , Button , Avatar , List , Comment } from 'antd' ;
4+ import { message , Card , Popover , Button , Avatar , List , Comment , Modal , Input } from 'antd' ;
55import {
66 RetweetOutlined , HeartOutlined , MessageOutlined , EllipsisOutlined , HeartTwoTone ,
77} from '@ant-design/icons' ;
@@ -16,18 +16,25 @@ import {
1616 REMOVE_POST_REQUEST ,
1717 UNLIKE_POST_REQUEST ,
1818 RETWEET_REQUEST ,
19- UPDATE_POST_REQUEST ,
19+ UPDATE_POST_REQUEST , REPORT_POST_REQUEST ,
2020} from '../reducers/post' ;
2121import FollowButton from './FollowButton' ;
22+ import useInput from '../hooks/useInput' ;
2223
24+ const { TextArea } = Input ;
2325moment . locale ( 'ko' ) ;
2426
2527const PostCard = ( { post } ) => {
2628 const dispatch = useDispatch ( ) ;
27- const { removePostLoading } = useSelector ( ( state ) => state . post ) ;
2829 const [ commentFormOpened , setCommentFormOpened ] = useState ( false ) ;
29- const id = useSelector ( ( state ) => state . user . me ?. id ) ;
30+ const [ modalVisible , setModalVisible ] = useState ( false ) ;
31+ const [ reportText , onChangeReportText ] = useInput ( '' ) ;
3032 const [ editMode , setEditMode ] = useState ( false ) ;
33+ const removePostLoading = useSelector ( ( state ) => state . post . removePostLoading ) ;
34+ const reportPostLoading = useSelector ( ( state ) => state . post . reportPostLoading ) ;
35+ const reportPostDone = useSelector ( ( state ) => state . post . reportPostDone ) ;
36+ const reportPostError = useSelector ( ( state ) => state . post . reportPostError ) ;
37+ const id = useSelector ( ( state ) => state . user . me ?. id ) ;
3138
3239 const onClickUpdate = useCallback ( ( ) => {
3340 setEditMode ( true ) ;
@@ -89,6 +96,35 @@ const PostCard = ({ post }) => {
8996 } ) ;
9097 } , [ id ] ) ;
9198
99+ const onClickReport = useCallback ( ( ) => {
100+ console . log ( '신고' , post . id ) ;
101+ setModalVisible ( true ) ;
102+ } ) ;
103+
104+ const onCloseModal = useCallback ( ( ) => {
105+ setModalVisible ( false ) ;
106+ } , [ ] ) ;
107+
108+ const onSubmitReport = useCallback ( ( ) => {
109+ console . log ( id , post . id , reportText ) ;
110+ dispatch ( {
111+ type : REPORT_POST_REQUEST ,
112+ data : {
113+ postId : post . id ,
114+ content : reportText ,
115+ } ,
116+ } ) ;
117+ } , [ reportText ] ) ;
118+
119+ useEffect ( ( ) => {
120+ if ( reportPostDone ) {
121+ setModalVisible ( false ) ;
122+ }
123+ if ( reportPostError ) {
124+ setModalVisible ( false ) ;
125+ }
126+ } , [ reportPostDone , reportPostError ] ) ;
127+
92128 const liked = post . Likers . find ( ( v ) => v . id === id ) ;
93129 return (
94130 < div style = { { marginBottom : 20 } } >
@@ -111,7 +147,7 @@ const PostCard = ({ post }) => {
111147 < Button type = "danger" loading = { removePostLoading } onClick = { onRemovePost } > 삭제</ Button >
112148 </ >
113149 )
114- : < Button > 신고</ Button > }
150+ : < Button onClick = { onClickReport } > 신고</ Button > }
115151 </ Button . Group >
116152 ) }
117153 >
@@ -121,6 +157,17 @@ const PostCard = ({ post }) => {
121157 title = { post . RetweetId ? `${ post . User . nickname } 님이 리트윗하셨습니다.` : null }
122158 extra = { id && < FollowButton post = { post } /> }
123159 >
160+ < Modal
161+ title = "신고하기"
162+ visible = { modalVisible }
163+ onOk = { onSubmitReport }
164+ confirmLoading = { reportPostLoading }
165+ onCancel = { onCloseModal }
166+ >
167+ < form >
168+ < TextArea value = { reportText } onChange = { onChangeReportText } />
169+ </ form >
170+ </ Modal >
124171 { post . RetweetId && post . Retweet
125172 ? (
126173 < Card
0 commit comments