2020-08-31 18:10:36 +02:00
|
|
|
import React, { useState, useContext, MouseEvent } from 'react';
|
2020-08-12 20:52:53 +02:00
|
|
|
import Collapse from '@material-ui/core/Collapse';
|
2020-08-17 22:05:13 +02:00
|
|
|
import ExpandIcon from '../assets/expand.png';
|
2020-09-28 20:16:54 +02:00
|
|
|
import { Course, Group, GroupType } from '../types/index';
|
2020-08-17 22:05:13 +02:00
|
|
|
import { coursesContext } from '../contexts/CoursesProvider';
|
2020-08-17 21:15:26 +02:00
|
|
|
import styled from 'styled-components';
|
|
|
|
import { makeStyles } from '@material-ui/core/styles';
|
2020-09-28 18:54:53 +02:00
|
|
|
import { ReactComponent as CloseIcon } from '../assets/close.svg';
|
2020-08-12 20:52:53 +02:00
|
|
|
|
2020-08-17 21:15:26 +02:00
|
|
|
interface ClassExandIconProps {
|
|
|
|
isSelected: boolean;
|
|
|
|
}
|
|
|
|
|
2020-08-17 23:56:34 +02:00
|
|
|
const CourseStyled = styled.div`
|
2020-08-17 21:15:26 +02:00
|
|
|
display: flex;
|
2020-10-08 20:21:52 +02:00
|
|
|
min-height: 40px;
|
2020-08-17 21:15:26 +02:00
|
|
|
background-color: rgb(100, 181, 246) !important;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
flex-direction: column;
|
|
|
|
margin-top: 10px;
|
|
|
|
padding-top: 10px;
|
|
|
|
padding-bottom: 10px;
|
|
|
|
border-radius: 10px;
|
|
|
|
cursor: pointer;
|
|
|
|
align-items: stretch;
|
2020-09-28 18:54:53 +02:00
|
|
|
position: relative;
|
2020-10-08 20:21:52 +02:00
|
|
|
box-shadow: 9px 9px 8px -2px rgba(0,0,0,0.59);
|
2020-08-17 21:15:26 +02:00
|
|
|
`;
|
|
|
|
|
2020-08-17 23:56:34 +02:00
|
|
|
const CourseNameStyled = styled.div`
|
2020-10-08 20:21:52 +02:00
|
|
|
padding-top:20px;
|
|
|
|
padding-bottom:10px;
|
|
|
|
padding-left:35px;
|
|
|
|
padding-right:35px;
|
2020-08-17 21:15:26 +02:00
|
|
|
`;
|
|
|
|
|
2020-10-01 19:51:06 +02:00
|
|
|
interface ClassGroupProps {
|
|
|
|
groupType: GroupType;
|
2020-09-28 20:16:54 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 20:21:52 +02:00
|
|
|
const ClassGroupStyled = styled.div`
|
|
|
|
position:relative;
|
2020-08-17 21:15:26 +02:00
|
|
|
padding-top: 1px;
|
|
|
|
padding-bottom: 1px;
|
|
|
|
:hover {
|
|
|
|
cursor: pointer;
|
2020-10-08 20:21:52 +02:00
|
|
|
background-color:#9ED3FF;
|
2020-08-17 21:15:26 +02:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const ClassExandIconStyled = styled.img<ClassExandIconProps>`
|
2020-08-17 22:05:13 +02:00
|
|
|
margin-top: 5px;
|
|
|
|
width: 20px;
|
|
|
|
transition: 0.2s;
|
|
|
|
transform: ${(props) => (props.isSelected ? 'scaleY(-1);' : 'scaleY(1);')};
|
|
|
|
`;
|
2020-08-17 21:15:26 +02:00
|
|
|
|
2020-10-21 12:58:24 +02:00
|
|
|
const TypeClass = styled.div`
|
2020-10-16 18:53:34 +02:00
|
|
|
font-size:12px;
|
2020-10-08 20:21:52 +02:00
|
|
|
position:absolute;
|
2020-10-16 18:53:34 +02:00
|
|
|
border-radius:15px;
|
|
|
|
background-color:#00506B;
|
|
|
|
border:2px solid;
|
|
|
|
min-width:45px;
|
2020-10-08 20:21:52 +02:00
|
|
|
top:5px;
|
2020-10-16 18:53:34 +02:00
|
|
|
left:5px;
|
|
|
|
color:white;
|
|
|
|
font-weight:bold;
|
2020-10-08 20:21:52 +02:00
|
|
|
`;
|
|
|
|
|
2020-08-17 21:15:26 +02:00
|
|
|
const useStyles = makeStyles({
|
|
|
|
expanded: {
|
2020-08-17 22:05:13 +02:00
|
|
|
maxHeight: '244px',
|
|
|
|
overflowY: 'auto',
|
2020-10-08 20:21:52 +02:00
|
|
|
'&::-webkit-scrollbar': {
|
2020-08-17 22:05:13 +02:00
|
|
|
width: '0.4em',
|
2020-08-17 21:15:26 +02:00
|
|
|
},
|
2020-10-08 20:21:52 +02:00
|
|
|
'&::-webkit-scrollbar-track': {
|
2020-08-17 22:05:13 +02:00
|
|
|
'-webkit-box-shadow': 'inset 0 0 6px rgba(1,0,0,0.1)',
|
2020-08-17 21:15:26 +02:00
|
|
|
},
|
2020-10-08 20:21:52 +02:00
|
|
|
'&::-webkit-scrollbar-thumb': {
|
2020-08-17 22:05:13 +02:00
|
|
|
borderRadius: '10px',
|
2020-08-17 21:15:26 +02:00
|
|
|
backgroundColor: '#d4b851',
|
2020-08-17 22:05:13 +02:00
|
|
|
outline: '1px solid slategrey',
|
|
|
|
},
|
|
|
|
},
|
2020-08-17 21:15:26 +02:00
|
|
|
});
|
|
|
|
|
2020-09-28 18:54:53 +02:00
|
|
|
const DeleteFromBasketIcon = styled(CloseIcon)`
|
2020-09-28 18:36:38 +02:00
|
|
|
width: 20px;
|
|
|
|
cursor: pointer;
|
2020-09-28 18:54:53 +02:00
|
|
|
position: absolute;
|
2020-10-08 20:21:52 +02:00
|
|
|
left: 230px;
|
|
|
|
top: -5px;
|
2020-09-28 18:54:53 +02:00
|
|
|
&:hover {
|
2020-10-08 20:21:52 +02:00
|
|
|
fill: white;
|
2020-09-28 18:36:38 +02:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2020-08-17 22:05:13 +02:00
|
|
|
interface CourseCardProps {
|
|
|
|
course: Course;
|
|
|
|
}
|
|
|
|
|
2020-09-28 18:36:38 +02:00
|
|
|
export const CourseCard = ({ course }: CourseCardProps) => {
|
2020-08-17 21:15:26 +02:00
|
|
|
const classes = useStyles();
|
2020-09-28 18:36:38 +02:00
|
|
|
const { addGroup, deleteFromBasket } = useContext(coursesContext)!;
|
2020-10-01 19:51:06 +02:00
|
|
|
const [isSelected, setSelected] = useState(false);
|
|
|
|
const groups = course.lectures === undefined ? course.classes : [...course.lectures, ...course.classes];
|
2020-08-17 23:56:34 +02:00
|
|
|
|
2020-08-23 17:22:50 +02:00
|
|
|
const onGroupClick = (group: Group, id: number) => addGroup(group, id);
|
2020-08-12 20:52:53 +02:00
|
|
|
|
|
|
|
return (
|
2020-08-31 18:10:36 +02:00
|
|
|
<CourseStyled>
|
2020-09-28 18:54:53 +02:00
|
|
|
<DeleteFromBasketIcon onClick={() => deleteFromBasket(course.id)}></DeleteFromBasketIcon>
|
2020-08-31 18:10:36 +02:00
|
|
|
<CourseNameStyled onClick={() => setSelected(!isSelected)}>{course.name}</CourseNameStyled>
|
2020-08-17 21:15:26 +02:00
|
|
|
<Collapse className={classes.expanded} in={isSelected} timeout="auto" unmountOnExit>
|
2020-10-01 19:51:06 +02:00
|
|
|
{groups
|
|
|
|
.sort((a, b) => b.type.localeCompare(a.type))
|
|
|
|
.map((group, index) => (
|
2020-10-08 20:21:52 +02:00
|
|
|
<ClassGroupStyled key={index} onClick={() => onGroupClick(group, course.id)}>
|
2020-10-21 12:58:24 +02:00
|
|
|
<TypeClass>{group.type==="CLASS"? "Ćw." : "Wyk."}</TypeClass>
|
2020-10-01 19:51:06 +02:00
|
|
|
<p>
|
|
|
|
{group.time} {group.room} <br></br> {group.lecturer}
|
|
|
|
</p>
|
|
|
|
</ClassGroupStyled>
|
|
|
|
))}
|
2020-08-12 20:52:53 +02:00
|
|
|
</Collapse>
|
2020-08-31 18:10:36 +02:00
|
|
|
<div onClick={() => setSelected(!isSelected)}>
|
2020-08-17 21:15:26 +02:00
|
|
|
<ClassExandIconStyled isSelected={isSelected} alt="expand" src={ExpandIcon} />
|
2020-08-12 20:52:53 +02:00
|
|
|
</div>
|
2020-08-17 23:56:34 +02:00
|
|
|
</CourseStyled>
|
2020-08-12 20:52:53 +02:00
|
|
|
);
|
2020-08-17 23:56:34 +02:00
|
|
|
};
|