2020-08-12 20:52:53 +02:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
import Collapse from '@material-ui/core/Collapse';
|
2020-08-17 22:05:13 +02:00
|
|
|
import ExpandIcon from '../assets/expand.png';
|
|
|
|
import { Course, Group } from '../types/index';
|
|
|
|
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-08-12 20:52:53 +02:00
|
|
|
|
2020-08-17 21:15:26 +02:00
|
|
|
interface ClassExandIconProps {
|
|
|
|
isSelected: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ClassStyled = styled.div`
|
|
|
|
display: flex;
|
|
|
|
min-height: 50px;
|
|
|
|
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;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const ClassNameStyled = styled.div`
|
|
|
|
padding-top: 10px;
|
|
|
|
padding-bottom: 10px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const ClassGroupStyled = styled.div`
|
|
|
|
padding-top: 1px;
|
|
|
|
padding-bottom: 1px;
|
|
|
|
:hover {
|
|
|
|
cursor: pointer;
|
|
|
|
transition: 1s;
|
|
|
|
background-color: #8bc8fb;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
const useStyles = makeStyles({
|
|
|
|
expanded: {
|
2020-08-17 22:05:13 +02:00
|
|
|
maxHeight: '244px',
|
|
|
|
overflowY: 'auto',
|
2020-08-17 21:15:26 +02:00
|
|
|
},
|
|
|
|
'@global': {
|
|
|
|
'*::-webkit-scrollbar': {
|
2020-08-17 22:05:13 +02:00
|
|
|
width: '0.4em',
|
2020-08-17 21:15:26 +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
|
|
|
},
|
|
|
|
'*::-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-08-17 22:05:13 +02:00
|
|
|
interface CourseCardProps {
|
|
|
|
onCardClick: (e: React.MouseEvent) => void;
|
|
|
|
course: Course;
|
|
|
|
id: string;
|
|
|
|
isSelected: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function CourseCard({ onCardClick, course, id, isSelected }: CourseCardProps) {
|
2020-08-17 21:15:26 +02:00
|
|
|
const classes = useStyles();
|
2020-08-12 20:52:53 +02:00
|
|
|
const { addGroup, courses } = useContext(coursesContext)!;
|
|
|
|
|
|
|
|
function onGroupClick(group: Group) {
|
|
|
|
addGroup(group);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-08-17 21:15:26 +02:00
|
|
|
<ClassStyled onClick={onCardClick} id={id}>
|
|
|
|
<ClassNameStyled>{course.name}</ClassNameStyled>
|
|
|
|
<Collapse className={classes.expanded} in={isSelected} timeout="auto" unmountOnExit>
|
2020-08-12 20:52:53 +02:00
|
|
|
{courses.map((course, index) => (
|
|
|
|
<>
|
|
|
|
{course.groups.map((group, index) => (
|
2020-08-17 22:05:13 +02:00
|
|
|
<ClassGroupStyled key={index} onClick={() => onGroupClick(group)}>
|
2020-08-12 20:52:53 +02:00
|
|
|
<p>
|
|
|
|
{group.time} {group.room} <br></br> {group.lecturer}
|
|
|
|
</p>{' '}
|
2020-08-17 21:15:26 +02:00
|
|
|
</ClassGroupStyled>
|
2020-08-12 20:52:53 +02:00
|
|
|
))}
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</Collapse>
|
|
|
|
<div onClick={onCardClick} id={id}>
|
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 21:15:26 +02:00
|
|
|
</ClassStyled>
|
2020-08-12 20:52:53 +02:00
|
|
|
);
|
|
|
|
}
|