ShowContent.js
2.2 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
import './App.css';
import axios from "axios";
import { useEffect, useState } from 'react';
import './ShowContent.css'
function ShowContent() {
const [title, setTitle] = useState('');
const [content, setContent] = useState('');
const [item, setItem] = useState('');
const getContent = async() => {
const contId = window.location.pathname.substring(13);
axios.get(`/api/get/${contId}`).then((res)=>{
setTitle(res.data.title);
setContent(res.data.content);
setItem(res.data.date+' '+res.data.time);
console.log(title, content, item);
});
};
const modify = async()=>{
const contId = window.location.pathname.substring(13);
const getPassword = await prompt('비밀번호를 입력해주세요');
const call = { 'id': contId, 'password': getPassword};
console.log(call);
if(getPassword != null){
axios.post(`/api/isPassEqual`, call).then((res)=>{
console.log(res);
if(res.data == 'success'){
window.location.href = `/modifycontent/${contId}`;
} else if (res.data == 'failed'){
alert('비밀번호가 틀렸습니다.');
}
});
}
};
const delete_ = async()=>{
const contId = window.location.pathname.substring(13);
const getPassword = await prompt('비밀번호를 입력해주세요');
const call = { 'id': contId, 'password': getPassword};
if(getPassword != null){
axios.post(`/api/isPassEqual`, call).then((res)=>{
console.log(res, '삭제');
if(res.data == 'success'){
axios.delete(`/api/delete/${contId}`).then((res)=>{
window.location.href = `/mealtalk`;
});
} else if (res.data == 'failed'){
alert('비밀번호가 틀렸습니다.');
}
});
}
}
useEffect(()=>{
getContent();
}, []);
return (
<div className='contentOuter'>
<div className='content'>{title}</div>
<div className='content'>{content}</div>
<div className='content'><p>{item}</p><button onMouseUp={modify}>수정</button><button onMouseUp={delete_}>삭제</button></div>
</div>
);
};
export default ShowContent;