CommuPageYes.js
1.86 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
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 CommuPageYes() {
const [list2, setList2] = useState([]);
const moveToToday = () => {window.location.href = '/mealtalk';}
const moveToWriting = () => {window.location.href = '/writing';}
const yesterInnerContent = async () =>{
let today = new Date();
let year = today.getFullYear(); // 년도
let month = today.getMonth() + 1; // 월
let date = today.getDate() -1; // 날짜
let todayDate = year+'-0'+month+'-0'+date; // date에 넣을 문자열
const arr = (await axios.get(`/api/getList/:${todayDate}`)).data;
var idArray = [];
for(var id of arr) idArray.push(id);
axios.post('/api/get',{idArray:idArray}).then((res)=>{
const reverseArr = res.data.reverse();
setList2(reverseArr);
console.log(reverseArr);
})
};
useEffect(() => {
yesterInnerContent();
}, []);
return (
<div className='commuPage'>
<div>
{list2.map((item, index) => {
return (
<InnerContent key={index} id= {item.id} time={item.time} title={item.title} content={item.content} />
)
})}
</div>
<div>
<button onClick={moveToWriting}>글 작성</button>
<button onClick={moveToToday}>오늘 보기</button>
</div>
</div>
);
}
//첫번째: 오늘 메뉴/ 두번째: 오늘 메뉴에 대한 이야기/ 세번째: 어제 메뉴에 대한 이야기
export default CommuPageYes;