All files / src/components Rightbar.tsx

77.78% Statements 7/9
100% Branches 0/0
33.33% Functions 1/3
87.5% Lines 7/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64            2x                                         2x                                           2x 4x   4x 4x 4x                  
import React, { useContext } from 'react';
import { CourseCard } from './CourseCard';
import { coursesContext } from '../contexts/CoursesProvider';
import styled from 'styled-components';
import { debounce } from '../utils/index';
 
const RightbarWrapper = styled.div`
  padding: 15px;
  text-align: center;
  height: 100%;
  width: 350px;
  overflow-y: scroll;
  ::-webkit-scrollbar-track {
    border-radius: 10px;
  }
  ::-webkit-scrollbar {
    width: 5px;
    border-style: none;
  }
  ::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background-color: #4b4b4b;
  }
  background-color: white;
  border-radius: 5px;
  box-shadow: 3px 3px 3px -2px rgba(0, 0, 0, 0.59);
`;
const SaveButton = styled.div`
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
  background-color: #43a047;
  border-radius: 10px;
  cursor: pointer;
  height: 40px;
  margin-bottom: 10px;
  &:hover {
    color: #ffffff;
    box-shadow: 0px 5px 4px 0px rgba(0, 0, 0, 0.24);
  }
 
  &:active {
    background-color: #54c457;
  }
 
  box-shadow: 3px 3px 3px 0px rgba(0, 0, 0, 0.75);
`;
 
export const Rightbar = () => {
  const { selectBasketCourses, saveBasket, userID } = useContext(coursesContext)!;
 
  const basketCourses = selectBasketCourses();
  const handleSave = debounce(() => saveBasket(userID), 500);
  return (
    <RightbarWrapper>
      <SaveButton onClick={handleSave}>ZAPISZ</SaveButton>
      {basketCourses.map((course) => (
        <CourseCard course={course} key={course.id} />
      ))}
    </RightbarWrapper>
  );
};