Didn't convert to table but managed to change stylings accordingly
This commit is contained in:
parent
d30852b97d
commit
9f531de1a5
@ -7,19 +7,19 @@ import styled from 'styled-components';
|
|||||||
|
|
||||||
const Wrapper = styled.div`
|
const Wrapper = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
|
height: calc(100vh - 80px);
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const App = () => {
|
export const App = () => {
|
||||||
const [isOpenTransfer, setOpenTransfer] = useState(false);
|
const [isOpenTransfer, setOpenTransfer] = useState(false);
|
||||||
|
|
||||||
|
|
||||||
const handleTransfer = () => {
|
const handleTransfer = () => {
|
||||||
setOpenTransfer(!isOpenTransfer);
|
setOpenTransfer(!isOpenTransfer);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Topbar handleTransfer={handleTransfer} />
|
<Topbar handleTransfer={handleTransfer} />
|
||||||
<Transfer isOpen={isOpenTransfer} handleClose={handleTransfer} />
|
<Transfer isOpen={isOpenTransfer} handleClose={handleTransfer} />
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<Scheduler />
|
<Scheduler />
|
||||||
|
@ -9,8 +9,8 @@ const RightbarStyled = styled.div`
|
|||||||
padding-right: 15px;
|
padding-right: 15px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-family: Lato;
|
font-family: Lato;
|
||||||
|
height: 100%;
|
||||||
width: 300px;
|
width: 300px;
|
||||||
height: 85vh;
|
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
::-webkit-scrollbar-track {
|
::-webkit-scrollbar-track {
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useEffect, useLayoutEffect, useRef } from 'react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { SchedulerEvents } from './SchedulerEvents';
|
import { SchedulerEvents } from './SchedulerEvents';
|
||||||
import { days, hours } from '../constants/index';
|
import { days, hours } from '../constants/index';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components/macro';
|
||||||
|
|
||||||
const SchedulerWrapper = styled.div`
|
const SchedulerWrapper = styled.div`
|
||||||
flex-grow: 3;
|
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
|
flex-grow: 1;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const TableBody = styled.div`
|
const TableBody = styled.div`
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
`;
|
`;
|
||||||
@ -22,36 +21,46 @@ const TableRow = styled.div`
|
|||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const TableCell = styled.div`
|
|
||||||
border: 1px solid #ddd;
|
|
||||||
padding: 10px;
|
|
||||||
text-align: center;
|
|
||||||
flex: 1;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const TableHead = styled.div`
|
const TableHead = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const TableHeadCell = styled.div`
|
interface TableCellProps {
|
||||||
|
height: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TableCell = styled.div<TableCellProps>`
|
||||||
|
height: ${({ height }) => height}px;
|
||||||
border: 1px solid #ddd;
|
border: 1px solid #ddd;
|
||||||
padding: 10px;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const T = styled.table`
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
`;
|
||||||
|
|
||||||
export const Scheduler = () => {
|
export const Scheduler = () => {
|
||||||
const [currentEventsIds, setCurrentEventsIds] = useState<Array<string>>([]);
|
const [currentEventsIds, setCurrentEventsIds] = useState<Array<string>>([]);
|
||||||
const cellRef = useRef<HTMLDivElement>(null);
|
const cellRef = useRef<HTMLDivElement>(null);
|
||||||
const [cellWidth, setCellWidth] = useState(0);
|
const [cellWidth, setCellWidth] = useState(0);
|
||||||
const [cellTop, setCellTop] = useState(0);
|
const [cellTop, setCellTop] = useState(0);
|
||||||
|
|
||||||
|
const wrapperRef = useRef<HTMLDivElement>(null);
|
||||||
|
const [wrapperHeight, setWrapperHeight] = useState(0);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log(cellTop);
|
||||||
|
}, [cellTop]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleResize = () => {
|
const handleResize = () => {
|
||||||
if (cellRef.current) {
|
if (cellRef.current && wrapperRef.current) {
|
||||||
setCellWidth(cellRef.current.getBoundingClientRect().width);
|
setCellWidth(cellRef.current.getBoundingClientRect().width);
|
||||||
setCellTop(cellRef.current.getBoundingClientRect().top);
|
setCellTop(cellRef.current.getBoundingClientRect().top);
|
||||||
|
setWrapperHeight(wrapperRef.current.getBoundingClientRect().height);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
handleResize();
|
handleResize();
|
||||||
@ -81,10 +90,12 @@ export const Scheduler = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SchedulerWrapper>
|
<SchedulerWrapper ref={wrapperRef}>
|
||||||
<TableHead>
|
<TableHead>
|
||||||
{days.map((day, index) => (
|
{days.map((day, index) => (
|
||||||
<TableHeadCell key={index}>{day}</TableHeadCell>
|
<TableCell height={wrapperHeight / 13} key={index} ref={cellRef}>
|
||||||
|
{day}
|
||||||
|
</TableCell>
|
||||||
))}
|
))}
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
@ -92,15 +103,17 @@ export const Scheduler = () => {
|
|||||||
<TableRow key={indexRow}>
|
<TableRow key={indexRow}>
|
||||||
{[hour, '', '', '', '', ''].map((value, indexCell) =>
|
{[hour, '', '', '', '', ''].map((value, indexCell) =>
|
||||||
indexRow === 0 && indexCell === 1 ? (
|
indexRow === 0 && indexCell === 1 ? (
|
||||||
<TableCell key={`${indexRow}${indexCell}`} ref={cellRef}></TableCell>
|
<TableCell height={wrapperHeight / 13} key={`${indexRow}${indexCell}`}></TableCell>
|
||||||
) : (
|
) : (
|
||||||
<TableCell key={`${indexRow}${indexCell}`}>{value}</TableCell>
|
<TableCell height={wrapperHeight / 13} key={`${indexRow}${indexCell}`}>
|
||||||
|
{value}
|
||||||
|
</TableCell>
|
||||||
),
|
),
|
||||||
)}
|
)}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
<SchedulerEvents cellTop={cellTop} cellWidth={cellWidth} />
|
<SchedulerEvents cellTop={cellTop} cellWidth={cellWidth} cellHeight={wrapperHeight / 13} />
|
||||||
</SchedulerWrapper>
|
</SchedulerWrapper>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -2,14 +2,14 @@ import React, { useContext, useEffect, useState } from 'react';
|
|||||||
import { SchedulerRow } from './SchedulerRow';
|
import { SchedulerRow } from './SchedulerRow';
|
||||||
import { coursesContext } from '../contexts/CoursesProvider';
|
import { coursesContext } from '../contexts/CoursesProvider';
|
||||||
import { Group, Basket } from '../types';
|
import { Group, Basket } from '../types';
|
||||||
import classes from '*.module.css';
|
|
||||||
|
|
||||||
interface SchedulerEventsProps {
|
interface SchedulerEventsProps {
|
||||||
cellTop: number;
|
cellTop: number;
|
||||||
cellWidth: number;
|
cellWidth: number;
|
||||||
|
cellHeight: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SchedulerEvents = ({ cellTop, cellWidth }: SchedulerEventsProps) => {
|
export const SchedulerEvents = ({ cellTop, cellWidth, cellHeight }: SchedulerEventsProps) => {
|
||||||
const { basket } = useContext(coursesContext)!;
|
const { basket } = useContext(coursesContext)!;
|
||||||
|
|
||||||
const [choosenGroupsMappedToEvents, setChoosenGroupsMappedToEvents] = useState<any>([]);
|
const [choosenGroupsMappedToEvents, setChoosenGroupsMappedToEvents] = useState<any>([]);
|
||||||
@ -56,13 +56,22 @@ export const SchedulerEvents = ({ cellTop, cellWidth }: SchedulerEventsProps) =>
|
|||||||
})}
|
})}
|
||||||
indexRow={index}
|
indexRow={index}
|
||||||
cellTop={
|
cellTop={
|
||||||
index == 3
|
index === 0
|
||||||
? cellTop + (25 + 80 * index)
|
? cellTop + (cellHeight + cellHeight * 2 * index + cellHeight / 4)
|
||||||
: index < 3
|
: index === 1
|
||||||
? cellTop + (12 + 80 * index)
|
? cellTop + (cellHeight + cellHeight * 2 * index)
|
||||||
: cellTop + (25 + 80 * 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
|
||||||
}
|
}
|
||||||
cellWidth={cellWidth}
|
cellWidth={cellWidth}
|
||||||
|
cellHeight={cellHeight}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
@ -6,14 +6,15 @@ interface SchedulerEventProps {
|
|||||||
eventIndex: number;
|
eventIndex: number;
|
||||||
cellTop: number;
|
cellTop: number;
|
||||||
cellWidth: number;
|
cellWidth: number;
|
||||||
|
cellHeight: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SchedulerEvent = styled.div<SchedulerEventProps>`
|
const SchedulerEvent = styled.div<SchedulerEventProps>`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: ${(props) => props.cellTop}px;
|
top: ${({ cellTop }) => cellTop}px;
|
||||||
left: ${(props) => props.cellWidth + 5 + props.cellWidth * props.eventIndex}px;
|
left: ${({ cellWidth, eventIndex }) => cellWidth + 5 + cellWidth * eventIndex}px;
|
||||||
width: ${(props) => (props.cellWidth * 2) / 3}px;
|
width: ${({ cellWidth }) => (cellWidth * 2) / 3}px;
|
||||||
height: 69px;
|
height: ${({ cellHeight }) => (cellHeight * 2 * 3) / 4}px;
|
||||||
background-color: lightblue;
|
background-color: lightblue;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
`;
|
`;
|
||||||
@ -23,11 +24,10 @@ interface SchedulerRowProps {
|
|||||||
indexRow: number;
|
indexRow: number;
|
||||||
cellTop: number;
|
cellTop: number;
|
||||||
cellWidth: number;
|
cellWidth: number;
|
||||||
|
cellHeight: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SchedulerRow = ({ groups, indexRow, cellTop, cellWidth }: SchedulerRowProps) => {
|
export const SchedulerRow = ({ groups, indexRow, cellTop, cellWidth, cellHeight }: SchedulerRowProps) => {
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{[...Array(5)].map((_, eventIndex) => (
|
{[...Array(5)].map((_, eventIndex) => (
|
||||||
@ -35,12 +35,11 @@ export const SchedulerRow = ({ groups, indexRow, cellTop, cellWidth }: Scheduler
|
|||||||
eventIndex={eventIndex}
|
eventIndex={eventIndex}
|
||||||
cellTop={cellTop}
|
cellTop={cellTop}
|
||||||
cellWidth={cellWidth}
|
cellWidth={cellWidth}
|
||||||
|
cellHeight={cellHeight}
|
||||||
key={eventIndex}
|
key={eventIndex}
|
||||||
id={`eventRow${indexRow}eventCol${eventIndex}`}
|
id={`eventRow${indexRow}eventCol${eventIndex}`}
|
||||||
>
|
>
|
||||||
{groups.map((group, index) =>
|
{groups.map((group, index) => group.day === eventIndex && <div key={index}>{groups[index]?.lecturer}</div>)}
|
||||||
group.day === eventIndex && <div key={index}>{groups[index]?.lecturer}</div>,
|
|
||||||
)}
|
|
||||||
</SchedulerEvent>
|
</SchedulerEvent>
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
|
@ -102,9 +102,9 @@ export default function ({ handleTransfer }: TopbarProps) {
|
|||||||
<TopbarInputStyled>
|
<TopbarInputStyled>
|
||||||
<TopbarInputIconStyled alt="search" src={Search} />
|
<TopbarInputIconStyled alt="search" src={Search} />
|
||||||
<TopbarInputFieldStyled>
|
<TopbarInputFieldStyled>
|
||||||
<Dropdown clearInput={clearInput} handleClearInput={handleClearInput}/>
|
<Dropdown clearInput={clearInput} handleClearInput={handleClearInput} />
|
||||||
</TopbarInputFieldStyled>
|
</TopbarInputFieldStyled>
|
||||||
<TopbarInputIconStyled alt="close" src={CloseIcon} onClick={handleClearInput}/>
|
<TopbarInputIconStyled alt="close" src={CloseIcon} onClick={handleClearInput} />
|
||||||
</TopbarInputStyled>
|
</TopbarInputStyled>
|
||||||
<TopbarIconBox>
|
<TopbarIconBox>
|
||||||
<TopbarIcon alt="transfer" src={Transfer} onClick={handleTransfer} />
|
<TopbarIcon alt="transfer" src={Transfer} onClick={handleTransfer} />
|
||||||
@ -114,4 +114,4 @@ export default function ({ handleTransfer }: TopbarProps) {
|
|||||||
</TopbarIconBox>
|
</TopbarIconBox>
|
||||||
</Topbar>
|
</Topbar>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user