2020-08-12 04:13:14 +02:00
|
|
|
import React, { useContext, useEffect, useState } from 'react';
|
2020-08-17 22:05:13 +02:00
|
|
|
import { SchedulerRow } from './SchedulerRow';
|
|
|
|
import { coursesContext } from '../contexts/CoursesProvider';
|
|
|
|
import { Group } from '../types';
|
2020-08-09 20:44:35 +02:00
|
|
|
|
|
|
|
interface SchedulerEventsProps {
|
|
|
|
cellTop: number;
|
|
|
|
cellWidth: number;
|
|
|
|
}
|
|
|
|
|
2020-08-12 04:13:14 +02:00
|
|
|
export const SchedulerEvents = ({ cellTop, cellWidth }: SchedulerEventsProps) => {
|
2020-08-12 20:52:53 +02:00
|
|
|
const { choosenGroups } = useContext(coursesContext)!;
|
2020-08-09 21:41:52 +02:00
|
|
|
|
|
|
|
const [groupsMappedToEvents, setGroupsMappedToEvents] = useState<any>([]);
|
|
|
|
|
2020-08-12 20:52:53 +02:00
|
|
|
// const groups: Array<Group> = [{ id: "5", day: "4", time: "11.45", courser: "dr Dorota Blinkiewicz", room: "A2-3" },
|
|
|
|
// { id: "28", day: "1", time: "13.45", courser: "dr Barbara Kołodziejczak", room: "D-3" },
|
|
|
|
// { id: "69", day: "4", time: "15.30", courser: "dr Karol Gierszewski", room: "A2-3" }];
|
2020-08-09 21:41:52 +02:00
|
|
|
|
|
|
|
interface GroupTimeToEventRowMapping {
|
2020-08-12 04:13:14 +02:00
|
|
|
[time: string]: number;
|
2020-08-09 21:41:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const groupTimeToEventRowMapping: GroupTimeToEventRowMapping = {
|
2020-08-12 20:52:53 +02:00
|
|
|
'08.15': 0,
|
2020-08-12 04:13:14 +02:00
|
|
|
'10.00': 1,
|
|
|
|
'11.45': 2,
|
|
|
|
'13.45': 3,
|
|
|
|
'15.30': 4,
|
|
|
|
'17.15': 5,
|
|
|
|
};
|
2020-08-09 21:41:52 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
function mapGroupTimeToEventRow(groups: Array<Group>) {
|
2020-08-12 17:14:21 +02:00
|
|
|
const groupsMappedToEventsTemp = [];
|
2020-08-09 21:41:52 +02:00
|
|
|
for (const group of groups) {
|
2020-08-12 04:13:14 +02:00
|
|
|
const groupTime = group.time;
|
2020-08-09 21:41:52 +02:00
|
|
|
const eventRow: number = groupTimeToEventRowMapping[groupTime];
|
2020-08-12 04:13:14 +02:00
|
|
|
const groupMappedToEvent: any = {
|
|
|
|
id: group.id,
|
|
|
|
day: group.day,
|
|
|
|
eventRow: eventRow,
|
|
|
|
lecturer: group.lecturer,
|
|
|
|
room: group.room,
|
|
|
|
};
|
2020-08-09 21:41:52 +02:00
|
|
|
setGroupsMappedToEvents((groupsMappedToEvents: any) => [...groupsMappedToEvents, groupMappedToEvent]);
|
|
|
|
}
|
2020-08-12 04:13:14 +02:00
|
|
|
function alternative(groups: Array<Group>) {
|
|
|
|
const groupsMapped = choosenGroups.map(({ id, day, lecturer, room, time }) => ({
|
|
|
|
id,
|
|
|
|
day,
|
|
|
|
lecturer,
|
|
|
|
room,
|
|
|
|
eventRow: groupTimeToEventRowMapping[time],
|
|
|
|
}));
|
|
|
|
setGroupsMappedToEvents(groupsMapped);
|
|
|
|
}
|
2020-08-09 20:44:35 +02:00
|
|
|
}
|
2020-08-09 21:41:52 +02:00
|
|
|
mapGroupTimeToEventRow(choosenGroups);
|
|
|
|
}, [choosenGroups]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
}, [groupsMappedToEvents]);
|
2020-08-09 20:44:35 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2020-08-12 04:13:14 +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>
|
|
|
|
);
|
|
|
|
};
|