CommuPage.js
1.65 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
import './App.css';
import axios from "axios";
import { useEffect, useState } from 'react';
import './CommuPage.css'
function InnerContent(props) {
return (
<div className='outer' value={props.id} onMouseUp={() => { window.location.href = `/showcontent/${props.id}`; }}>
<div className='inner'>{props.title}</div>
<div className='inner'>{props.content}</div>
<div className='inner'>{props.time}</div>
</div>
);
}
function CommuPage() {
const [list, setList] = useState([]);
const moveToYesterDay = () => {window.location.href = '/mealtalk/yesterday';}
const moveToWriting = () => {window.location.href = '/writing';}
const todayInnerContent = async () => { // 게시글 목록 가져오기
const arr = (await axios.get('/api/getList')).data;
var idArray = [];
for(var id of arr) idArray.push(id);
axios.post('/api/get',{idArray:idArray}).then((res)=>{
const reverseArr = res.data.reverse();
setList(reverseArr);
console.log(reverseArr);
})
};
useEffect(() => {
todayInnerContent();
}, []);
return (
<div className='commuPage'>
<div>
{list.map((item, index) => {
return (
<InnerContent key={index} id= {item.id} title={item.title} content={item.content} time={item.time} />
)
})}
</div>
<div>
<button onClick={moveToWriting}>글 작성</button>
<button onClick={moveToYesterDay}>어제 보기</button>
</div>
</div>
);
}
//첫번째: 오늘 메뉴/ 두번째: 오늘 메뉴에 대한 이야기/ 세번째: 어제 메뉴에 대한 이야기
export default CommuPage;