2020-10-26 23:14:23 +01:00
|
|
|
import React, { MouseEvent, useState } from 'react';
|
2020-09-28 20:16:54 +02:00
|
|
|
import { Group, GroupType } from '../types';
|
2020-09-19 00:17:23 +02:00
|
|
|
import styled from 'styled-components/macro';
|
|
|
|
import Popover from '@material-ui/core/Popover';
|
|
|
|
import Typography from '@material-ui/core/Typography';
|
|
|
|
import { makeStyles, createStyles, Theme } from '@material-ui/core/styles';
|
|
|
|
|
|
|
|
const useStyles = makeStyles((theme: Theme) =>
|
|
|
|
createStyles({
|
|
|
|
popover: {
|
|
|
|
pointerEvents: 'none',
|
|
|
|
},
|
|
|
|
paper: {
|
|
|
|
padding: theme.spacing(1),
|
2020-09-20 20:23:46 +02:00
|
|
|
marginLeft: 5,
|
2020-09-28 18:36:38 +02:00
|
|
|
textAlign: 'center',
|
2020-09-19 00:17:23 +02:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2020-08-12 04:13:14 +02:00
|
|
|
|
|
|
|
interface SchedulerEventProps {
|
|
|
|
eventIndex: number;
|
|
|
|
cellTop: number;
|
|
|
|
cellWidth: number;
|
2020-08-29 18:52:03 +02:00
|
|
|
cellHeight: number;
|
2020-08-12 04:13:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const SchedulerEvent = styled.div<SchedulerEventProps>`
|
|
|
|
position: absolute;
|
2020-09-19 00:17:23 +02:00
|
|
|
display: flex;
|
2020-08-29 18:52:03 +02:00
|
|
|
top: ${({ cellTop }) => cellTop}px;
|
|
|
|
left: ${({ cellWidth, eventIndex }) => cellWidth + 5 + cellWidth * eventIndex}px;
|
2020-09-19 00:17:23 +02:00
|
|
|
width: ${({ cellWidth }) => (cellWidth * 2.5) / 3}px;
|
2020-11-13 23:05:10 +01:00
|
|
|
height: ${({ cellHeight }) => cellHeight * 3}px;
|
2020-09-11 18:56:14 +02:00
|
|
|
z-index: 2;
|
|
|
|
`;
|
|
|
|
|
2020-10-26 23:14:23 +01:00
|
|
|
interface ClassesProps {
|
2020-09-28 20:16:54 +02:00
|
|
|
cellWidth: number;
|
|
|
|
cellHeight: number;
|
|
|
|
groupType: GroupType;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Classes = styled.div<ClassesProps>`
|
2020-09-28 18:36:38 +02:00
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
2020-08-12 04:13:14 +02:00
|
|
|
z-index: 2;
|
2020-09-11 18:56:14 +02:00
|
|
|
border-radius: 10px;
|
2020-09-20 20:23:46 +02:00
|
|
|
width: ${({ cellWidth }) => (cellWidth * 2.5) / 3}px;
|
2020-11-13 23:05:10 +01:00
|
|
|
height: ${({ cellHeight }) => (cellHeight * 2 * 3) / 2}px;
|
2020-11-03 00:59:42 +01:00
|
|
|
padding-left: 10px;
|
|
|
|
text-align: left;
|
2020-11-08 13:40:11 +01:00
|
|
|
background-color: ${({ groupType }) => (groupType === 'CLASS' ? '#FFDC61' : '#9ed3ff')};
|
2020-10-26 23:14:23 +01:00
|
|
|
box-shadow: 9px 9px 8px -2px rgba(0, 0, 0, 0.59);
|
2020-08-12 04:13:14 +02:00
|
|
|
`;
|
2020-08-09 20:44:35 +02:00
|
|
|
|
|
|
|
interface SchedulerRowProps {
|
2020-09-18 23:00:11 +02:00
|
|
|
groups: Array<Group & { name: string }>;
|
2020-08-09 20:44:35 +02:00
|
|
|
indexRow: number;
|
|
|
|
cellTop: number;
|
|
|
|
cellWidth: number;
|
2020-08-29 18:52:03 +02:00
|
|
|
cellHeight: number;
|
2020-08-09 20:44:35 +02:00
|
|
|
}
|
|
|
|
|
2020-09-19 00:17:23 +02:00
|
|
|
export const SchedulerRow = ({ groups, indexRow, cellTop, cellWidth, cellHeight }: SchedulerRowProps) => {
|
|
|
|
const classes = useStyles();
|
|
|
|
const [anchorEl, setAnchorEl] = React.useState<HTMLDivElement | null>(null);
|
2020-09-28 18:36:38 +02:00
|
|
|
const [popoverId, setPopoverId] = useState<string | null>(null);
|
|
|
|
|
2020-09-19 00:17:23 +02:00
|
|
|
//looks weird
|
|
|
|
const handlePopoverOpen = (event: MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => {
|
|
|
|
setAnchorEl(event.currentTarget);
|
2020-09-28 18:36:38 +02:00
|
|
|
setPopoverId(event.currentTarget.id);
|
2020-09-19 00:17:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const handlePopoverClose = () => {
|
|
|
|
setAnchorEl(null);
|
2020-09-20 20:23:46 +02:00
|
|
|
setPopoverId(null);
|
2020-09-19 00:17:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const open = Boolean(anchorEl);
|
|
|
|
|
2020-08-09 20:44:35 +02:00
|
|
|
return (
|
2020-11-13 23:05:10 +01:00
|
|
|
<div>
|
2020-08-18 00:21:21 +02:00
|
|
|
{[...Array(5)].map((_, eventIndex) => (
|
2020-08-12 04:13:14 +02:00
|
|
|
<SchedulerEvent
|
|
|
|
eventIndex={eventIndex}
|
|
|
|
cellTop={cellTop}
|
|
|
|
cellWidth={cellWidth}
|
2020-08-29 18:52:03 +02:00
|
|
|
cellHeight={cellHeight}
|
2020-08-18 00:21:21 +02:00
|
|
|
key={eventIndex}
|
2020-08-09 21:41:52 +02:00
|
|
|
id={`eventRow${indexRow}eventCol${eventIndex}`}
|
2020-08-09 20:44:35 +02:00
|
|
|
>
|
2020-09-11 18:56:14 +02:00
|
|
|
{groups.map(
|
|
|
|
(group, index) =>
|
|
|
|
group.day === eventIndex && (
|
2020-11-03 00:59:42 +01:00
|
|
|
<>
|
2020-09-19 00:17:23 +02:00
|
|
|
<Classes
|
2020-09-28 20:16:54 +02:00
|
|
|
groupType={group.type}
|
2020-09-19 00:17:23 +02:00
|
|
|
cellWidth={cellWidth}
|
|
|
|
cellHeight={cellHeight}
|
2020-09-20 20:23:46 +02:00
|
|
|
id={`eventRow${indexRow}eventCol${eventIndex}${index}`}
|
2020-09-19 00:17:23 +02:00
|
|
|
key={index}
|
2020-09-20 20:23:46 +02:00
|
|
|
aria-owns={open ? `mouse-over-popover` : undefined}
|
2020-09-19 00:17:23 +02:00
|
|
|
aria-haspopup="true"
|
2020-09-20 20:23:46 +02:00
|
|
|
onMouseEnter={(e) => handlePopoverOpen(e)}
|
2020-09-19 00:17:23 +02:00
|
|
|
onMouseLeave={handlePopoverClose}
|
|
|
|
>
|
2020-11-03 00:59:42 +01:00
|
|
|
<div>
|
|
|
|
<p style={{ fontWeight: 700 }}>{groups[index].name}</p>
|
2020-11-08 13:40:11 +01:00
|
|
|
<p >{groups[index].room}</p>
|
2020-11-03 00:59:42 +01:00
|
|
|
</div>
|
2020-09-19 00:17:23 +02:00
|
|
|
</Classes>
|
|
|
|
<Popover
|
2020-09-20 20:23:46 +02:00
|
|
|
id={`mouse-over-popover`}
|
2020-09-19 00:17:23 +02:00
|
|
|
className={classes.popover}
|
|
|
|
classes={{
|
|
|
|
paper: classes.paper,
|
|
|
|
}}
|
2020-09-28 18:36:38 +02:00
|
|
|
open={popoverId === `eventRow${indexRow}eventCol${eventIndex}${index}`}
|
2020-09-19 00:17:23 +02:00
|
|
|
anchorEl={anchorEl}
|
|
|
|
anchorOrigin={{
|
2020-09-20 20:23:46 +02:00
|
|
|
vertical: 'top',
|
|
|
|
horizontal: 'right',
|
2020-09-19 00:17:23 +02:00
|
|
|
}}
|
|
|
|
transformOrigin={{
|
2020-09-20 20:23:46 +02:00
|
|
|
vertical: 'center',
|
2020-09-19 00:17:23 +02:00
|
|
|
horizontal: 'left',
|
|
|
|
}}
|
|
|
|
onClose={handlePopoverClose}
|
|
|
|
disableRestoreFocus
|
|
|
|
>
|
2020-09-28 18:36:38 +02:00
|
|
|
<Typography>
|
|
|
|
<p>{groups[index].name}</p>
|
|
|
|
<p>{groups[index].lecturer}</p>
|
|
|
|
<p>{groups[index].room}</p>
|
|
|
|
</Typography>
|
2020-09-19 00:17:23 +02:00
|
|
|
</Popover>
|
2020-11-03 00:59:42 +01:00
|
|
|
</>
|
2020-09-11 18:56:14 +02:00
|
|
|
),
|
|
|
|
)}
|
2020-08-12 04:13:14 +02:00
|
|
|
</SchedulerEvent>
|
2020-08-09 20:44:35 +02:00
|
|
|
))}
|
2020-11-13 23:05:10 +01:00
|
|
|
</div>
|
2020-08-09 20:44:35 +02:00
|
|
|
);
|
|
|
|
};
|