2020-08-12 04:13:14 +02:00
|
|
|
import React, { useContext, useEffect, useState } from 'react';
|
|
|
|
import { SchedulerRow } from '../SchedulerRow';
|
|
|
|
import { LecturesContext } from '../../../contexts/LecturesProvider';
|
|
|
|
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) => {
|
|
|
|
const { choosenGroups } = useContext(LecturesContext)!;
|
2020-08-09 21:41:52 +02:00
|
|
|
|
|
|
|
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 {
|
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 04:13:14 +02:00
|
|
|
'8.15': 0,
|
|
|
|
'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>) {
|
|
|
|
for (const group of groups) {
|
|
|
|
console.log(group);
|
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(() => {
|
|
|
|
console.log(groupsMappedToEvents);
|
|
|
|
}, [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>
|
|
|
|
);
|
|
|
|
};
|