frontend/src/components/Scheduler/index.tsx

160 lines
4.4 KiB
TypeScript
Raw Normal View History

2020-07-30 18:06:27 +02:00
import React, { useEffect, useContext } from "react";
2020-07-20 17:53:50 +02:00
import { useState } from "react";
import "./index.scss";
import { SchedulerEvent } from "./SchedulerEvent";
import { Column } from "./Column";
2020-07-30 18:06:27 +02:00
import { LecturesContext } from "../../businesslogic/LecturesProvider";
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",
"20:00",
"21: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";
let wrap: "wrap" = "wrap";
const tbodyStyles = {
width: 900,
height: 560,
backgroundColor: "blue",
display: "flex",
flexDirection: column,
// flexWrap: wrap
}
const rowStyles = {
display: "flex",
flexDirection: row,
}
const cellStyles = {
border: "1px solid #ddd",
padding: "10px",
textAlign: center,
flex: 1,
}
2020-07-20 17:53:50 +02:00
let terms = ["Zawsze", "jest pora", "na kurde", "lody", "koral"];
export const Scheduler = () => {
const [currentEventsIds, setCurrentEventsIds] = useState<Array<string>>([]);
2020-07-30 18:06:27 +02:00
const { choosenGroups } = useContext(LecturesContext);
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]);
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)}`;
setCurrentEventsIds((currentEventsIds) => [...currentEventsIds, eventId]);
};
return (
<>
2020-07-30 18:06:27 +02:00
<div className="scheduler" >
2020-07-20 17:53:50 +02:00
<div className="thead">
{days.map((day, index) => (
<div className="th" key={index}>
{day}
</div>
))}
</div>
2020-08-05 23:54:30 +02:00
<div style={tbodyStyles}>
{hours.map((hour, index) => (
<div style={rowStyles}>{
[hour, "", "", "", "", ""].map((value) => (
<div style={cellStyles}>{value}</div>
))}</div>
))}
</div>
<div>
{["", "", "", "", ""].map((value, index) => (
<div style={{ position: "absolute", top: 150 + 10, left: 155 + 150 * index, width: 100, height: 60, backgroundColor: "black", zIndex: 2 }}>
</div>
))}
</div>
<div>
{["", "", "", "", ""].map((value, index) => (
<div style={{ position: "absolute", top: 150 + 80, left: 155 + 150 * index, width: 100, height: 60, backgroundColor: "black", zIndex: 2 }}>
</div>
))}
</div> <div>
{["", "", "", "", ""].map((value, index) => (
<div style={{ position: "absolute", top: 150 + 150, left: 155 + 150 * index, width: 100, height: 60, backgroundColor: "black", zIndex: 2 }}>
</div>
))}
</div> <div>
{["", "", "", "", ""].map((value, index) => (
<div style={{ position: "absolute", top: 150 + 230, left: 155 + 150 * index, width: 100, height: 60, backgroundColor: "black", zIndex: 2 }}>
</div>
))}
</div> <div>
{["", "", "", "", ""].map((value, index) => (
<div style={{ position: "absolute", top: 150 + 300, left: 155 + 150 * index, width: 100, height: 60, backgroundColor: "black", zIndex: 2 }}>
</div>
))}
</div> <div>
{["", "", "", "", ""].map((value, index) => (
<div style={{ position: "absolute", top: 150 + 370, left: 155 + 150 * index, width: 100, height: 60, backgroundColor: "black", zIndex: 2 }}>
</div>
))}
</div>
{/* <div className="tbody">
2020-07-30 18:06:27 +02:00
<Column hours={hours} isEventable={false} />
2020-07-20 17:53:50 +02:00
{terms.map((_, colIndex) => (
2020-07-30 18:06:27 +02:00
<Column
hours={hours}
handleClick={handleClick}
colIndex={colIndex}
isEventable={true}
>
2020-07-20 17:53:50 +02:00
<SchedulerEvent events={events} colIndex={colIndex} />
</Column>
))}
2020-08-05 23:54:30 +02:00
</div> */}
2020-07-20 17:53:50 +02:00
</div>
</>
);
};