From c1cf27d82874b2d44393d474f70a606cc82a23a1 Mon Sep 17 00:00:00 2001 From: wrzesinski-hubert Date: Mon, 28 Sep 2020 18:36:38 +0200 Subject: [PATCH] delete from basket --- src/components/CourseCard.tsx | 19 +++++++++++++++--- src/components/SchedulerRow.tsx | 34 +++++++++++++++++++------------- src/contexts/CoursesProvider.tsx | 6 +++++- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/components/CourseCard.tsx b/src/components/CourseCard.tsx index 802b707..dad01fe 100644 --- a/src/components/CourseCard.tsx +++ b/src/components/CourseCard.tsx @@ -5,6 +5,7 @@ import { Course, Group } from '../types/index'; import { coursesContext } from '../contexts/CoursesProvider'; import styled from 'styled-components'; import { makeStyles } from '@material-ui/core/styles'; +import CloseIcon from '../assets/close.svg'; interface ClassExandIconProps { isSelected: boolean; @@ -23,6 +24,7 @@ const CourseStyled = styled.div` border-radius: 10px; cursor: pointer; align-items: stretch; + position:relative; `; const CourseNameStyled = styled.div` @@ -67,21 +69,32 @@ const useStyles = makeStyles({ }, }); +const DeleteFromBasketIcon = styled.img` + width: 20px; + cursor: pointer; + position:absolute; + left:235px; + top:5px; + :hover{ + color:red; + } +`; + interface CourseCardProps { course: Course; } -export const CourseCard = ({course }: CourseCardProps) => { - +export const CourseCard = ({ course }: CourseCardProps) => { const [isSelected, setSelected] = useState(false); const classes = useStyles(); - const { addGroup } = useContext(coursesContext)!; + const { addGroup, deleteFromBasket } = useContext(coursesContext)!; const onGroupClick = (group: Group, id: number) => addGroup(group, id); return ( + deleteFromBasket(course.id)}> setSelected(!isSelected)}>{course.name} {course.groups.map((group, index) => ( diff --git a/src/components/SchedulerRow.tsx b/src/components/SchedulerRow.tsx index fd4f5da..4e0dbe6 100644 --- a/src/components/SchedulerRow.tsx +++ b/src/components/SchedulerRow.tsx @@ -13,7 +13,7 @@ const useStyles = makeStyles((theme: Theme) => paper: { padding: theme.spacing(1), marginLeft: 5, - textAlign:"center" + textAlign: 'center', }, }), ); @@ -36,14 +36,16 @@ const SchedulerEvent = styled.div` `; const Classes = styled.div` + display: flex; + justify-content: center; + align-items: center; z-index: 2; border-radius: 10px; - padding-left: 5px; background-color: rgb(100, 181, 246); width: ${({ cellWidth }) => (cellWidth * 2.5) / 3}px; height: ${({ cellHeight }) => (cellHeight * 2 * 3) / 4}px; - margin-right:5px; - text-align:center; + margin-right: 5px; + text-align: center; `; interface SchedulerRowProps { @@ -57,12 +59,12 @@ interface SchedulerRowProps { export const SchedulerRow = ({ groups, indexRow, cellTop, cellWidth, cellHeight }: SchedulerRowProps) => { const classes = useStyles(); const [anchorEl, setAnchorEl] = React.useState(null); - const [popoverId, setPopoverId] = useState(null); - + const [popoverId, setPopoverId] = useState(null); + //looks weird const handlePopoverOpen = (event: MouseEvent) => { setAnchorEl(event.currentTarget); - setPopoverId(event.currentTarget.id) + setPopoverId(event.currentTarget.id); }; const handlePopoverClose = () => { @@ -72,10 +74,6 @@ export const SchedulerRow = ({ groups, indexRow, cellTop, cellWidth, cellHeight const open = Boolean(anchorEl); - useEffect(()=>{ - console.log("1231312"+popoverId); - },[popoverId]) - return ( <> {[...Array(5)].map((_, eventIndex) => ( @@ -103,7 +101,11 @@ export const SchedulerRow = ({ groups, indexRow, cellTop, cellWidth, cellHeight onMouseEnter={(e) => handlePopoverOpen(e)} onMouseLeave={handlePopoverClose} > - {groups[index].name}

{groups[index].room}

+

+ {groups[index].name} +

+ {groups[index].room} +

-

{groups[index].name}

{groups[index].lecturer}

{groups[index].room}

+ +

{groups[index].name}

+

{groups[index].lecturer}

+

{groups[index].room}

+
), diff --git a/src/contexts/CoursesProvider.tsx b/src/contexts/CoursesProvider.tsx index 0c64967..70c7167 100644 --- a/src/contexts/CoursesProvider.tsx +++ b/src/contexts/CoursesProvider.tsx @@ -7,6 +7,7 @@ interface CourseContext { basket: Array; addToBasket: (courses: Basket) => void; addGroup: (group: Group, id: number) => void; + deleteFromBasket: (id: number) => void; } export const coursesContext = createContext(null); @@ -21,6 +22,9 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => { const addToBasket = (course: Basket) => setBasket([...basket, course]); + const deleteFromBasket = (id: number) => setBasket(basket.filter(course => course.id !== id)); + + useEffect(() => { console.log('BASKET'); console.log(basket); @@ -52,6 +56,6 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => { }, []); return ( - {children} + {children} ); };