GridItem.js
1.54 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
import { useContext, useEffect, useState } from "react";
import localforage from "localforage";
import { toYMD, toYMDStr } from "../utils/Dates";
import { CalendarStateContext } from "../pages/Calendar";
import ScheduleItem from "./ScheduleItem";
import axios from "axios";
const GridItem = ({ targetDate }) => {
const { state } = useContext(CalendarStateContext);
const { month: calMonth } = toYMD(state.date);
const { month, date } = toYMD(targetDate);
const [schedules, setSchedules] = useState();
useEffect(() => {
async function loadScheduleItems() {
const params = {
userID: await localforage.getItem("userID"),
date: toYMDStr(targetDate, "-"),
day: targetDate.getDay(),
};
const { data: scdate } = await axios.get(
"http://localhost:3001/db/schedules_date",
{ params }
);
const { data: sctime } = await axios.get(
"http://localhost:3001/db/schedules_time",
{ params }
);
const { data: scrpeat } = await axios.get(
"http://localhost:3001/db/schedules_repeat",
{ params }
);
setSchedules(scrpeat.concat(scdate, sctime));
}
loadScheduleItems();
}, [targetDate]);
return (
<div className="GridItem" relative={month - calMonth || null}>
<span className="date">
{calMonth !== month ? month + "/" + date : date}
</span>
{schedules &&
schedules.map((sche, index) => (
<ScheduleItem key={index} schedule={sche} />
))}
</div>
);
};
export default GridItem;