2020-08-09 20:44:35 +02:00
|
|
|
import React, { useEffect, useRef } from "react";
|
2020-07-20 17:53:50 +02:00
|
|
|
import { useState } from "react";
|
|
|
|
import "./index.scss";
|
2020-08-09 20:44:35 +02:00
|
|
|
import { SchedulerEvents } from "./SchedulerEvents";
|
2020-07-20 17:53:50 +02:00
|
|
|
const days = ["", "poniedziałek", "wtorek", "środa", "czwartek", "piątek"];
|
|
|
|
|
|
|
|
const hours = [
|
|
|
|
"8:00",
|
|
|
|
"9:00",
|
|
|
|
"10:00",
|
|
|
|
"11:00",
|
|
|
|
"12:00",
|
|
|
|
"13:00",
|
|
|
|
"14:00",
|
|
|
|
"15:00",
|
|
|
|
"16:00",
|
|
|
|
"17:00",
|
|
|
|
"18:00",
|
|
|
|
"19:00",
|
|
|
|
];
|
|
|
|
|
|
|
|
let events: Array<number> = [];
|
|
|
|
for (let i = 0; i < hours.length / 2; i++) {
|
|
|
|
events.push(i);
|
|
|
|
}
|
|
|
|
|
2020-08-05 23:54:30 +02:00
|
|
|
let center: "center" = "center";
|
|
|
|
let row: "row" = "row";
|
|
|
|
let column: "column" = "column";
|
2020-08-09 20:44:35 +02:00
|
|
|
// const collapse: "collapse" = "collapse";
|
2020-08-05 23:54:30 +02:00
|
|
|
const tbodyStyles = {
|
2020-08-09 19:29:03 +02:00
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
2020-08-05 23:54:30 +02:00
|
|
|
display: "flex",
|
|
|
|
flexDirection: column,
|
2020-08-09 20:44:35 +02:00
|
|
|
};
|
2020-08-05 23:54:30 +02:00
|
|
|
|
|
|
|
const rowStyles = {
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: row,
|
2020-08-09 20:44:35 +02:00
|
|
|
};
|
2020-08-05 23:54:30 +02:00
|
|
|
|
|
|
|
const cellStyles = {
|
|
|
|
border: "1px solid #ddd",
|
|
|
|
padding: "10px",
|
|
|
|
textAlign: center,
|
|
|
|
flex: 1,
|
2020-08-09 20:44:35 +02:00
|
|
|
};
|
2020-08-05 23:54:30 +02:00
|
|
|
|
2020-08-09 19:29:03 +02:00
|
|
|
const theadStyles = {
|
|
|
|
display: "flex",
|
2020-08-09 20:44:35 +02:00
|
|
|
width: "100%",
|
|
|
|
};
|
2020-08-09 19:29:03 +02:00
|
|
|
|
2020-08-09 20:44:35 +02:00
|
|
|
// const scheduler = {
|
|
|
|
// marginTop: "20px",
|
|
|
|
// borderCollapse: collapse,
|
|
|
|
// };
|
2020-07-20 17:53:50 +02:00
|
|
|
|
|
|
|
export const Scheduler = () => {
|
|
|
|
const [currentEventsIds, setCurrentEventsIds] = useState<Array<string>>([]);
|
2020-08-09 19:29:03 +02:00
|
|
|
const cellRef = useRef<HTMLDivElement>(null);
|
|
|
|
const [cellWidth, setCellWidth] = useState(0);
|
|
|
|
const [cellTop, setCellTop] = useState(0);
|
2020-07-30 18:06:27 +02:00
|
|
|
|
2020-08-09 20:44:35 +02:00
|
|
|
|
2020-08-09 19:29:03 +02:00
|
|
|
useEffect(() => {
|
|
|
|
const handleResize = () => {
|
|
|
|
if (cellRef.current) {
|
|
|
|
setCellWidth(cellRef.current.getBoundingClientRect().width);
|
|
|
|
setCellTop(cellRef.current.getBoundingClientRect().top);
|
|
|
|
}
|
2020-08-09 20:44:35 +02:00
|
|
|
};
|
2020-08-09 19:29:03 +02:00
|
|
|
handleResize();
|
2020-08-09 20:44:35 +02:00
|
|
|
window.addEventListener("resize", handleResize);
|
2020-08-09 19:29:03 +02:00
|
|
|
}, []);
|
|
|
|
|
2020-07-20 17:53:50 +02:00
|
|
|
useEffect(() => {
|
|
|
|
const displayEvents = () => {
|
|
|
|
currentEventsIds.map((eventId: string) => {
|
|
|
|
const event = document.getElementById(eventId);
|
2020-07-30 18:06:27 +02:00
|
|
|
if (event) {
|
|
|
|
event.style.display = "block";
|
|
|
|
}
|
2020-07-20 17:53:50 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
displayEvents();
|
|
|
|
}, [currentEventsIds]);
|
|
|
|
|
2020-08-09 20:44:35 +02:00
|
|
|
// const handleClick = (e: React.MouseEvent) => {
|
|
|
|
// const cellId = e.currentTarget.id;
|
|
|
|
// const column = cellId.slice(0, 1);
|
|
|
|
// const row = cellId.slice(1);
|
|
|
|
// const eventId = `eventCol${column}eventRow${Math.floor(parseInt(row) / 2)}`;
|
2020-07-20 17:53:50 +02:00
|
|
|
|
2020-08-09 20:44:35 +02:00
|
|
|
// setCurrentEventsIds((currentEventsIds) => [...currentEventsIds, eventId]);
|
|
|
|
// };
|
2020-07-20 17:53:50 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2020-08-09 20:44:35 +02:00
|
|
|
<div className="scheduler">
|
2020-08-09 19:29:03 +02:00
|
|
|
<div style={theadStyles}>
|
2020-07-20 17:53:50 +02:00
|
|
|
{days.map((day, index) => (
|
|
|
|
<div className="th" key={index}>
|
|
|
|
{day}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
2020-08-05 23:54:30 +02:00
|
|
|
<div style={tbodyStyles}>
|
2020-08-09 19:29:03 +02:00
|
|
|
{hours.map((hour, indexRow) => (
|
2020-08-09 20:44:35 +02:00
|
|
|
<div key={indexRow} style={rowStyles}>
|
|
|
|
{[hour, "", "", "", "", ""].map((value, indexCell) =>
|
|
|
|
indexRow === 0 && indexCell === 1 ? (
|
|
|
|
<div key={`${indexRow}${indexCell}`} ref={cellRef} style={cellStyles}></div>
|
|
|
|
) : (
|
|
|
|
<div key={`${indexRow}${indexCell}`} style={cellStyles}>{value}</div>
|
|
|
|
)
|
|
|
|
)}
|
2020-08-05 23:54:30 +02:00
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
2020-08-09 20:44:35 +02:00
|
|
|
<SchedulerEvents cellTop={cellTop} cellWidth={cellWidth} />
|
2020-07-20 17:53:50 +02:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|