mainpage.js
3.01 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import './App.css';
import axios from "axios";
import { useEffect, useState } from 'react';
import './mainpage.css'
function InnerContent(props) {
return (
<div>
<div style={{ fontSize: '15px', height: '10px', width: '100%', backgroundColor: '#FDF5E6' }}>{props.title} {props.content}</div>
</div>
);
}
function MainPage() {
const [list, setList] = useState([{ title: '하이', content: '바보' }, { title: '하이2', content: '바보2' }, { title: '하이3', content: '바보3' }]);
let currentYear = new Date().getFullYear();
let currentMonth = new Date().getMonth() + 1;
let currentDate = new Date().getDate();
let today = currentYear + '/' + currentMonth + '/' + currentDate;
const todayMealTable = async () => {
axios.get("/api/todayMenu").then(
(res) => {
const makeTable = (arr_, dom_) => {
arr_.forEach((elem) => {
let span_ = document.createElement('div');
span_.innerHTML = elem;
dom_.appendChild(span_);
});
};
const lunchDom = document.getElementsByClassName('lunchTable')[0];
const dinnerDom = document.getElementsByClassName('dinnerTable')[0];
if (res.data !== "weekend") {
const index1 = res.data[0].indexOf(':');
const index2 = res.data[1].indexOf(':');
let lunchArr = res.data[0].substring(index1 + 1);
console.log(lunchArr)
let dinnerArr = res.data[1].substring(index2 + 1);
if (index1 !== -1) {
lunchArr = lunchArr.split(',');
}
if (index1 !== -1) {
dinnerArr = dinnerArr.split(',');
}
makeTable(lunchArr, lunchDom);
makeTable(dinnerArr, dinnerDom);
}
else{
makeTable(["오늘은"], lunchDom);
makeTable(["주말입니다."], dinnerDom);
}
}
)
};
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)=>{
setList(res.data);
console.log(res.data);
})
}
useEffect(() => {
todayMealTable();
todayInnerContent();
}, []);
return (
<div className='mainpage'>
<div>
<div className='haksikTitle'>
{today} 제2기숙사 학식
</div>
<div></div>
<div>점심</div>
<div>저녁</div>
<div className='lunchTable'></div>
<div className='dinnerTable'></div>
</div>
<div className='mainpageUnder'>
<div>메뉴에 대한 이야기</div>
<div>
{list.map((item, index) => {
return (
<InnerContent key={index} title={item.title} content={item.content} />
)
})}
</div>
</div>
</div>
);
}
//첫번째: 오늘 메뉴/ 두번째: 오늘 메뉴에 대한 이야기/ 세번째: 어제 메뉴에 대한 이야기
export default MainPage;