From 49341b025b2ac5c57ded674706421a3bf9aa3127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciek=20G=C5=82owacki?= Date: Fri, 13 Nov 2020 23:05:10 +0100 Subject: [PATCH] change change change --- src/components/Scheduler.tsx | 60 +++++++++++++++++++----------- src/components/SchedulerEvents.tsx | 26 ++++++------- src/components/SchedulerRow.tsx | 8 ++-- 3 files changed, 56 insertions(+), 38 deletions(-) diff --git a/src/components/Scheduler.tsx b/src/components/Scheduler.tsx index 6746765..c5d4795 100644 --- a/src/components/Scheduler.tsx +++ b/src/components/Scheduler.tsx @@ -1,11 +1,10 @@ -import React, { useEffect, MouseEvent, useRef } from 'react'; +import React, { useEffect, MouseEvent, useRef, useCallback, useLayoutEffect } from 'react'; import { useState } from 'react'; import { SchedulerEvents } from './SchedulerEvents'; import { days, hours } from '../constants/index'; import styled from 'styled-components/macro'; const SchedulerWrapper = styled.div` - display: flex; border-collapse: collapse; flex: 1; background-color: white; @@ -66,30 +65,46 @@ export const Scheduler = () => { const wrapperRef = useRef(null); const [wrapperHeight, setWrapperHeight] = useState(0); + const [, updateState] = useState(); + const forceUpdate = useCallback(() => updateState({}), []); + useEffect(() => { const handleResize = () => { - if (cellRef.current && wrapperRef.current) { + if (cellRef.current) { setCellWidth(cellRef.current.getBoundingClientRect().width); setCellTop(cellRef.current.getBoundingClientRect().top); - setWrapperHeight(wrapperRef.current.getBoundingClientRect().height); + cellRef.current.style.backgroundColor = "blue"; + console.log("XDDD") } + }; handleResize(); - window.addEventListener('resize', handleResize); }, []); + useEffect(() => { + const handleWrapperResize = () => { + if (wrapperRef.current) { + setWrapperHeight(wrapperRef.current.getBoundingClientRect().height); + } + } + window.addEventListener('resize', handleWrapperResize); + return () => window.removeEventListener('resize', handleWrapperResize); + + }, []) + + return ( <> {days.map((day, indexCell) => indexCell === 0 ? ( - + {day} ) : ( - + {day} ), @@ -102,22 +117,25 @@ export const Scheduler = () => { indexCell === 0 ? ( {value} - - ) : indexRow === 23 ? ( - + ) + : (indexRow === 0 && indexCell === 1) ? ( {value} - ) : indexCell === 5 ? ( - - {value} - - ) : indexRow % 2 !== 0 ? ( - - {value} - - ) : - {value} - + ) : indexRow === 23 ? ( + + {value} + + ) : indexCell === 5 ? ( + + {value} + + ) : indexRow % 2 !== 0 ? ( + + {value} + + ) : + {value} + )} ))} diff --git a/src/components/SchedulerEvents.tsx b/src/components/SchedulerEvents.tsx index da8c9db..8131d5e 100644 --- a/src/components/SchedulerEvents.tsx +++ b/src/components/SchedulerEvents.tsx @@ -11,7 +11,7 @@ interface SchedulerEventsProps { export const SchedulerEvents = ({ cellTop, cellWidth, cellHeight }: SchedulerEventsProps) => { const { basket } = useContext(coursesContext)!; - + console.log(`values: cellTop: ${cellTop}, cellWidth: ${cellWidth}, cellHeight: ${cellHeight}`); const [choosenGroupsMappedToEvents, setChoosenGroupsMappedToEvents] = useState([]); interface GroupTimeToEventRowMapping { @@ -33,7 +33,7 @@ export const SchedulerEvents = ({ cellTop, cellWidth, cellHeight }: SchedulerEve const merged = [...classes, ...lectures]; //deleted if statement, maybe it is needed - const groupsMapped = merged.map(({ id, day, lecturer, room, time, name,type }) => ({ + const groupsMapped = merged.map(({ id, day, lecturer, room, time, name, type }) => ({ id, day, lecturer, @@ -56,18 +56,18 @@ export const SchedulerEvents = ({ cellTop, cellWidth, cellHeight }: SchedulerEve indexRow={index} cellTop={ index === 0 - ? cellTop + (cellHeight + cellHeight * 2 * index + cellHeight / 4) + ? cellTop + cellHeight/2 : index === 1 - ? cellTop + (cellHeight + cellHeight * 2 * index) - : index === 2 - ? cellTop + (cellHeight + cellHeight * 2 * index - cellHeight / 4) - : index === 3 - ? cellTop + (cellHeight + cellHeight * 2 * index - cellHeight / 4) - : index === 4 - ? cellTop + (cellHeight + cellHeight * 2 * index - cellHeight / 2) - : index === 5 - ? cellTop + (cellHeight + cellHeight * 2 * index - (cellHeight * 3) / 4) - : 0 + ? cellTop + (cellHeight + cellHeight * 2 * index) + : index === 2 + ? cellTop + (cellHeight + cellHeight * 2 * index - cellHeight / 2) + : index === 3 + ? cellTop + (cellHeight + cellHeight * 2 * index - cellHeight / 2) + : index === 4 + ? cellTop + (cellHeight + cellHeight * 2 * index - cellHeight) + : index === 5 + ? cellTop + (cellHeight + cellHeight * 2 * index - (cellHeight * 3) / 2) + : 0 } cellWidth={cellWidth} cellHeight={cellHeight} diff --git a/src/components/SchedulerRow.tsx b/src/components/SchedulerRow.tsx index 9a04014..fbb14ab 100644 --- a/src/components/SchedulerRow.tsx +++ b/src/components/SchedulerRow.tsx @@ -31,7 +31,7 @@ const SchedulerEvent = styled.div` top: ${({ cellTop }) => cellTop}px; left: ${({ cellWidth, eventIndex }) => cellWidth + 5 + cellWidth * eventIndex}px; width: ${({ cellWidth }) => (cellWidth * 2.5) / 3}px; - height: ${({ cellHeight }) => (cellHeight * 2 * 3) / 4}px; + height: ${({ cellHeight }) => cellHeight * 3}px; z-index: 2; `; @@ -48,7 +48,7 @@ const Classes = styled.div` z-index: 2; border-radius: 10px; width: ${({ cellWidth }) => (cellWidth * 2.5) / 3}px; - height: ${({ cellHeight }) => (cellHeight * 2 * 3) / 4}px; + height: ${({ cellHeight }) => (cellHeight * 2 * 3) / 2}px; padding-left: 10px; text-align: left; background-color: ${({ groupType }) => (groupType === 'CLASS' ? '#FFDC61' : '#9ed3ff')}; @@ -82,7 +82,7 @@ export const SchedulerRow = ({ groups, indexRow, cellTop, cellWidth, cellHeight const open = Boolean(anchorEl); return ( - <> +
{[...Array(5)].map((_, eventIndex) => ( ))} - +
); };