frontend/src/components/RightBar/index.tsx

66 lines
1.7 KiB
TypeScript
Raw Normal View History

2020-08-12 04:13:14 +02:00
import React, { useState, useContext } from 'react';
2020-08-12 20:52:53 +02:00
import { CourseCard } from './CourseCard/index';
import { coursesContext } from '../../contexts/CoursesProvider';
2020-08-17 20:14:19 +02:00
import styled from 'styled-components';
2020-06-09 20:07:54 +02:00
2020-06-14 14:24:49 +02:00
interface RightBarProps {
2020-08-12 20:52:53 +02:00
onGroupMouseOver: (id: number, name: string) => void;
2020-06-14 14:24:49 +02:00
}
2020-06-07 15:57:51 +02:00
2020-08-17 20:14:19 +02:00
const RightBarStyled = styled.div`
padding-top: 10px;
padding-left: 15px;
padding-right: 15px;
text-align: center;
font-family: Lato;
width: 300px;
height: 85vh;
overflow-y: scroll;
::-webkit-scrollbar-track {
border-radius: 10px;
background-color: #f5f5f5;
}
::-webkit-scrollbar {
width: 12px;
background-color: #f5f5f5;
}
::-webkit-scrollbar-thumb {
border-radius: 10px;
background-color: #d4b851;
border: 1px solid;
}
`;
const RightBarTextStyled = styled.div`
border-bottom: 1px solid;
`;
2020-08-12 04:13:14 +02:00
export default function RightBar({ onGroupMouseOver }: RightBarProps) {
2020-07-24 18:59:45 +02:00
const [selectedCardId, setSelectedCardId] = useState<string | null>(null);
2020-06-07 15:57:51 +02:00
2020-08-12 20:52:53 +02:00
const { courses } = useContext(coursesContext)!;
2020-06-30 22:09:13 +02:00
2020-07-24 18:59:45 +02:00
const onCardClick = (e: React.MouseEvent) => {
const target = e.currentTarget as HTMLElement;
2020-08-12 04:13:14 +02:00
selectedCardId === target.id ? setSelectedCardId(null) : setSelectedCardId(target.id);
2020-07-24 18:59:45 +02:00
};
2020-06-30 22:09:13 +02:00
2020-07-24 18:59:45 +02:00
return (
2020-08-17 20:14:19 +02:00
<RightBarStyled>
<RightBarTextStyled>
2020-07-24 18:59:45 +02:00
Hubert Wrzesiński<br></br>
Semestr zimowy 2020/2021
2020-08-17 20:14:19 +02:00
</RightBarTextStyled>
2020-08-12 20:52:53 +02:00
{courses.map((course, index) => (
<CourseCard
course={course}
2020-07-24 18:59:45 +02:00
key={index}
id={index.toString()}
onGroupMouseOver={onGroupMouseOver}
onCardClick={onCardClick}
isSelected={selectedCardId === index.toString()}
/>
))}
2020-08-17 20:14:19 +02:00
</RightBarStyled>
2020-07-24 18:59:45 +02:00
);
2020-06-07 15:57:51 +02:00
}