ContentModal.js
2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React, {useState, useEffect} from 'react'
import Axios from 'axios'
import ReactHtmlParser from 'react-html-parser';
import { Button, Modal, Comment, Form } from 'semantic-ui-react'
import '../style/ContentModal.scss'
function ContentModal({element}) {
const [viewComment,setviewComment] = useState([]);
useEffect(()=>{
Axios.post('/api/comment/reply',{id : element.id}).then((response)=>{
setviewComment(response.data);
})
},[viewComment])
const handleClose = (event) => {
event.preventDefault();
setOpen(false);
}
const [open, setOpen] = useState(false)
const [BoardComment, setBoardComment] = useState("")
const onCommentHandler = (event) => {
setBoardComment(event.currentTarget.value)
console.log(BoardComment)
}
const onSubmitHandler = () => {
Axios.post('/api/comment/write',{
postid: element.id,
comment: BoardComment
})
.then((res)=>{
if(res.status === 200){
alert("댓글 작성을 완료하였습니다.")
setOpen(false);
}
}).catch((error) => {
console.log(error.response)
alert("댓글 작성을 실패하였습니다.")
})
}
return (
<Modal
onClose={() => setOpen(false)}
onOpen={() => setOpen(true)}
open={open}
trigger={<Button basic color='purple' className="ui animated button" tabIndex="0">
<div className="visible content">보기</div>
</Button>}
>
<Modal.Header><h2>{element.title}</h2></Modal.Header>
<Modal.Content>
<Modal.Description>
<div className="problems">
{ReactHtmlParser(element.post)}
</div>
</Modal.Description>
</Modal.Content>
<Modal.Content>
{viewComment&&viewComment.map(elem =>{
return <div className="ui segment">
<h2>{elem.userid}</h2>
<h4>{elem.comment}</h4>
</div>}
)}
</Modal.Content>
<Modal.Actions>
<Comment>
<Form reply>
<Form.TextArea value={BoardComment} onChange={onCommentHandler}/>
<div onClick={handleClose}>
<Button content='댓글 남기기' onClick={onSubmitHandler} labelPosition='left' icon='edit' primary />
<Button onClick={handleClose} color='black'>닫기</Button>
</div>
</Form>
</Comment>
</Modal.Actions>
</Modal>
)
}
export default ContentModal