ScheduleItem.js
2.64 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
import { useContext, useRef } from "react";
import zoomSymbol from "../assets/zoom.png";
import ecampusSymbol from "../assets/e-Campus.png";
import { CalendarStateContext } from "pages/Calendar";
const ScheduleItem = ({ schedule, finish }) => {
const { state: calState } = useContext(CalendarStateContext);
const {
name: subjectName,
nickname: subjectNickname,
uid: scheUID,
color: subjectColor,
url,
type,
label,
description = null,
detail = null,
startTime = null, //HHMMSS문자열
endTime = null,
table,
} = schedule;
let sTime = startTime ? startTime.substring(0, 5) : ""; //HHMM
let eTime = endTime ? endTime.substring(0, 5) : "";
const subStr =
calState.scope !== "month" ? `${subjectNickname || subjectName}` : null;
const selectSymbol = () => {
let symbol;
switch (type) {
case "zoom":
symbol = zoomSymbol;
break;
case "assignment":
symbol = ecampusSymbol;
break;
default:
}
return symbol;
};
const popupRef = useRef();
const thisRef = useRef();
const click = (e) => {
//Item
if (e.target.classList.contains("ss"))
popupRef.current.style.display = "grid";
else {
if (e.target.className === "spc") popupRef.current.style.display = "none"; //popup close
if (e.target.className === "spd") {
finish(table, scheUID);
thisRef.current.style.display = "none";
}
}
};
return (
<div
className="ScheduleItem ss"
style={{ borderColor: "#" + subjectColor }}
onClick={click}
ref={thisRef}
>
{subStr && (
<span className="s_substr ss">
{subStr} <br />
</span>
)}
<img className="s_symbol ss" src={selectSymbol()} alt="404" />
{startTime && <span className="s_start ss">{sTime}</span>}
{endTime && <span className="s_end ss">{eTime}</span>}
<span className="s_slabel ss">{label}</span>
<div className="s_popup" popup="true" ref={popupRef}>
<div className="spl">
<span>{subjectName}</span>
{url ? (
<a href={url} target="_blank">
{label}
</a>
) : (
<span>{label}</span>
)}
{(startTime || endTime) && <span>{sTime + " ~ " + eTime}</span>}
{description && <span>{description}</span>}
{detail && <div dangerouslySetInnerHTML={{ __html: detail }}></div>}
</div>
<div className="sp_btn">
<button className="spd">완료</button>
<button className="spc">닫기</button>
</div>
</div>
</div>
);
};
export default ScheduleItem;