diff --git a/src/components/CourseCard.tsx b/src/components/CourseCard.tsx index eb42f7b..802b707 100644 --- a/src/components/CourseCard.tsx +++ b/src/components/CourseCard.tsx @@ -1,4 +1,4 @@ -import React, { useContext, MouseEvent } from 'react'; +import React, { useState, useContext, MouseEvent } from 'react'; import Collapse from '@material-ui/core/Collapse'; import ExpandIcon from '../assets/expand.png'; import { Course, Group } from '../types/index'; @@ -68,13 +68,12 @@ const useStyles = makeStyles({ }); interface CourseCardProps { - onCardClick: (event: MouseEvent) => void; course: Course; - id: string; - isSelected: boolean; } -export const CourseCard = ({ onCardClick, course, id, isSelected }: CourseCardProps) => { +export const CourseCard = ({course }: CourseCardProps) => { + + const [isSelected, setSelected] = useState(false); const classes = useStyles(); const { addGroup } = useContext(coursesContext)!; @@ -82,8 +81,8 @@ export const CourseCard = ({ onCardClick, course, id, isSelected }: CourseCardPr const onGroupClick = (group: Group, id: number) => addGroup(group, id); return ( - - {course.name} + + setSelected(!isSelected)}>{course.name} {course.groups.map((group, index) => ( onGroupClick(group, course.id)}> @@ -93,7 +92,7 @@ export const CourseCard = ({ onCardClick, course, id, isSelected }: CourseCardPr ))} -
+
setSelected(!isSelected)}>
diff --git a/src/components/Rightbar.tsx b/src/components/Rightbar.tsx index 83c5a50..f5ae8f9 100644 --- a/src/components/Rightbar.tsx +++ b/src/components/Rightbar.tsx @@ -31,8 +31,6 @@ const RightbarTextStyled = styled.div` `; export const Rightbar = () => { - const [selectedCardId, setSelectedCardId] = useState(null); - const { courses, basket } = useContext(coursesContext)!; const getBasketGroups = () => { @@ -42,12 +40,6 @@ export const Rightbar = () => { const filteredCourses = getBasketGroups(); - //dziaƂa clunky - const onCardClick = (event: MouseEvent) => { - const target = event.currentTarget; - selectedCardId === target.id ? setSelectedCardId(null) : setSelectedCardId(target.id); - }; - //need to insert student name from db and course maybe based on current time or from db too return ( @@ -59,9 +51,6 @@ export const Rightbar = () => { ))}