2020-08-09 21:41:52 +02:00
|
|
|
import React, { useContext, useEffect, useState } from "react";
|
2020-08-09 20:44:35 +02:00
|
|
|
import { SchedulerRow } from "../SchedulerRow";
|
|
|
|
import { LecturesContext } from "../../../businesslogic/LecturesProvider";
|
2020-08-09 21:41:52 +02:00
|
|
|
import { Group } from "../../../businesslogic/types/group";
|
2020-08-09 20:44:35 +02:00
|
|
|
|
|
|
|
interface SchedulerEventsProps {
|
|
|
|
cellTop: number;
|
|
|
|
cellWidth: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const SchedulerEvents = ({
|
|
|
|
cellTop,
|
|
|
|
cellWidth,
|
|
|
|
}: SchedulerEventsProps) => {
|
2020-08-09 21:41:52 +02:00
|
|
|
// const handleEventClick = (e: React.MouseEvent) => {
|
|
|
|
// const eventDiv = e.target as HTMLDivElement;
|
|
|
|
// eventDiv.style.backgroundColor = "#1547C5";
|
|
|
|
// };
|
|
|
|
|
|
|
|
const { choosenGroups } = useContext(LecturesContext);
|
|
|
|
|
|
|
|
const [groupsMappedToEvents, setGroupsMappedToEvents] = useState<any>([]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const groups: Array<Group> = [{ id: "5", day: "4", time: "11.45", lecturer: "dr Dorota Blinkiewicz", room: "A2-3" },
|
|
|
|
// { id: "28", day: "1", time: "13.45", lecturer: "dr Barbara Kołodziejczak", room: "D-3" },
|
|
|
|
// { id: "69", day: "4", time: "15.30", lecturer: "dr Karol Gierszewski", room: "A2-3" }];
|
|
|
|
|
|
|
|
|
|
|
|
interface GroupTimeToEventRowMapping {
|
|
|
|
[time: string]: number
|
|
|
|
}
|
|
|
|
|
|
|
|
const groupTimeToEventRowMapping: GroupTimeToEventRowMapping = {
|
|
|
|
"8.15": 0,
|
|
|
|
"10.00": 1,
|
|
|
|
"11.45": 2,
|
|
|
|
"13.45": 3,
|
|
|
|
"15.30": 4,
|
|
|
|
"17.15": 5,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
function mapGroupTimeToEventRow(groups: Array<Group>) {
|
|
|
|
for (const group of groups) {
|
|
|
|
console.log(group);
|
|
|
|
const groupTime = group.time
|
|
|
|
const eventRow: number = groupTimeToEventRowMapping[groupTime];
|
|
|
|
const groupMappedToEvent: any = { id: group.id, day: group.day, eventRow: eventRow, lecturer: group.lecturer, room: group.room };
|
|
|
|
setGroupsMappedToEvents((groupsMappedToEvents: any) => [...groupsMappedToEvents, groupMappedToEvent]);
|
|
|
|
}
|
2020-08-09 20:44:35 +02:00
|
|
|
}
|
2020-08-09 21:41:52 +02:00
|
|
|
mapGroupTimeToEventRow(choosenGroups);
|
|
|
|
}, [choosenGroups]);
|
|
|
|
|
2020-08-09 20:44:35 +02:00
|
|
|
|
2020-08-09 21:41:52 +02:00
|
|
|
useEffect(() => {
|
|
|
|
console.log(groupsMappedToEvents);
|
2020-08-09 20:44:35 +02:00
|
|
|
|
2020-08-09 21:41:52 +02:00
|
|
|
}, [groupsMappedToEvents]);
|
2020-08-09 20:44:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
return (
|
2020-08-09 21:41:52 +02:00
|
|
|
|
|
|
|
|
2020-08-09 20:44:35 +02:00
|
|
|
<div>
|
2020-08-09 21:41:52 +02:00
|
|
|
{
|
|
|
|
[...Array(6)].map((_, index) => (
|
|
|
|
<SchedulerRow
|
|
|
|
key={index}
|
|
|
|
groups={groupsMappedToEvents.filter((group: any) => { return group.eventRow === index })}
|
|
|
|
indexRow={index}
|
|
|
|
cellTop={cellTop + (10 + 70 * index)}
|
|
|
|
cellWidth={cellWidth}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-09 20:44:35 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|