2020-10-04 17:21:51 +02:00
|
|
|
import React, { useContext } from 'react';
|
2020-08-17 22:05:13 +02:00
|
|
|
import { CourseCard } from './CourseCard';
|
|
|
|
import { coursesContext } from '../contexts/CoursesProvider';
|
2020-08-17 20:14:19 +02:00
|
|
|
import styled from 'styled-components';
|
2020-10-27 01:24:35 +01:00
|
|
|
import { debounce } from 'lodash';
|
2020-06-09 20:07:54 +02:00
|
|
|
|
2020-08-17 22:05:13 +02:00
|
|
|
const RightbarStyled = styled.div`
|
2020-08-17 20:14:19 +02:00
|
|
|
padding-top: 10px;
|
|
|
|
padding-left: 15px;
|
|
|
|
padding-right: 15px;
|
|
|
|
text-align: center;
|
2020-08-29 18:52:03 +02:00
|
|
|
height: 100%;
|
2020-08-17 20:14:19 +02:00
|
|
|
width: 300px;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
`;
|
2020-09-28 20:16:54 +02:00
|
|
|
const SaveButton = styled.div`
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
2020-11-01 21:41:16 +01:00
|
|
|
background-color: #417cab;
|
2020-09-28 20:16:54 +02:00
|
|
|
border-radius: 10px;
|
|
|
|
cursor: pointer;
|
|
|
|
height: 40px;
|
|
|
|
margin-bottom: 10px;
|
2020-10-01 20:06:38 +02:00
|
|
|
&:hover {
|
2020-10-08 20:21:52 +02:00
|
|
|
color: white;
|
2020-10-01 20:06:38 +02:00
|
|
|
}
|
2020-10-27 01:24:35 +01:00
|
|
|
box-shadow: 6px 6px 6px -2px rgba(0, 0, 0, 0.59);
|
2020-09-28 20:16:54 +02:00
|
|
|
`;
|
|
|
|
|
2020-08-17 23:56:34 +02:00
|
|
|
export const Rightbar = () => {
|
2020-10-01 20:06:38 +02:00
|
|
|
const { courses, basket, saveBasket } = useContext(coursesContext)!;
|
2020-08-23 17:22:50 +02:00
|
|
|
|
|
|
|
const getBasketGroups = () => {
|
2020-08-26 18:42:29 +02:00
|
|
|
const names = basket.map(({ name }) => name);
|
|
|
|
return courses.filter(({ name }) => names.includes(name));
|
2020-08-23 17:22:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const filteredCourses = getBasketGroups();
|
2020-06-30 22:09:13 +02:00
|
|
|
|
2020-10-27 01:24:35 +01:00
|
|
|
const handleSave = debounce(() => saveBasket(), 500);
|
2020-10-04 17:21:51 +02:00
|
|
|
|
2020-08-17 23:56:34 +02:00
|
|
|
//need to insert student name from db and course maybe based on current time or from db too
|
2020-07-24 18:59:45 +02:00
|
|
|
return (
|
2020-08-17 22:05:13 +02:00
|
|
|
<RightbarStyled>
|
2020-11-01 21:41:16 +01:00
|
|
|
<SaveButton onClick={handleSave}>ZAPISZ</SaveButton>
|
2020-08-23 17:22:50 +02:00
|
|
|
{filteredCourses.map((course, index) => (
|
2020-09-28 20:16:54 +02:00
|
|
|
<CourseCard course={course} key={index} />
|
2020-07-24 18:59:45 +02:00
|
|
|
))}
|
2020-08-17 22:05:13 +02:00
|
|
|
</RightbarStyled>
|
2020-07-24 18:59:45 +02:00
|
|
|
);
|
2020-08-17 23:56:34 +02:00
|
|
|
};
|