Commit 896a638c authored by Ermolaev Timur's avatar Ermolaev Timur

#28 Разделил части таблицы на разные компоненты

parent cce9a6c8
import { Grid } from "@mui/material";
const CalendarRow = ({children}) => {
return <>
<Grid
container
align='center'
sx={{borderBottom: '1px solid black', borderRight: '1px solid black', borderLeft: '1px solid black'}}
>
{children}
</Grid>
</>
};
export default CalendarRow;
import { Grid } from "@mui/material";
const CalendarSmallCell = ({children, xs}) => {
return <>
<Grid align='center' item xs={xs} sx={{borderRight: '1px solid black'}}>
{children}
</Grid>
</>
};
export default CalendarSmallCell;
\ No newline at end of file
import { Grid } from "@mui/material";
const CalendarStandartCell = ({children, xs, onClick}) => {
return <>
<Grid
item xs={xs}
sx={{borderRight: '1px solid black'}}
onClick={onClick}>
{children}
</Grid>
</>
};
export default CalendarStandartCell;
\ No newline at end of file
import { Grid, TextField } from "@mui/material";
import { useEffect, useState } from "react";
const CalendarTask = ({year, month, tasks, day, hours, setCurrentTask, onChange}) => {
const getTaskInDayCell = (tasks, day, hours) => {
const task = tasks.find(task=> {
if (year === task.infoForCell.startYear) {
if (month + 1 === task.infoForCell.startMonth) {
if (day.dayNumber === task.infoForCell.startDay) {
if ((task.infoForCell.endHour <= parseInt(hours.split(':')[0]) || task.infoForCell.startHour <= parseInt(hours.split(':')[0])) && (task.infoForCell.endHour > parseInt(hours.split(':')[0]))) {
return task
}
}
}
}
})
return task
}
let task = getTaskInDayCell(tasks, day, hours)
return (<>
{task ?
<Grid sx={{backgroundColor: 'lightgreen'}}>
<TextField
id={task.title}
variant="standard"
value={task.title}
name='title'
onClick={(e)=>{e.stopPropagation(); setCurrentTask(task)}}
onChange={onChange}>
</TextField>
</Grid>
: null }
</>)
};
export default CalendarTask;
\ No newline at end of file
import { Grid, TextField } from "@mui/material";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import CalendarRow from "./CalendarRow/CalendarRow";
import CalendarSmallCell from "./CalendarSmallCell/CalendarSmallCell";
import CalendarStandartCell from "./CalendarStandartCell.js/CalendarStandartCell";
import CalendarTask from "./CalendarTask/CalendarTask";
function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChangeCellTaskTitle, setCurrentTask}) { function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChangeCellTaskTitle, setCurrentTask}) {
const [hoursInDay, setHoursInDay] = useState(['8:00', '10:00', '12:00', '14:00', '16:00', '18:00', '20:00', '22:00', '6:00']) const [hoursInDay, setHoursInDay] = useState(['8:00', '10:00', '12:00', '14:00', '16:00', '18:00', '20:00', '22:00', '6:00'])
const [daysInMonth, setDaysInMonth] = useState([]) const [daysInMonth, setDaysInMonth] = useState([])
const [cellSizes, setCellSizes] = useState({})
useEffect(()=>{
const cells = hoursInDay.length
const xs = 11/cells
setCellSizes(()=>{
return {smallCell: 0.5, standarCell: xs}
})
}, [])
useEffect(()=>{ useEffect(()=>{
setNewMonthDays() setNewMonthDays()
}, [month, year]) }, [month])
const getDaysInMonth = () => { const getDaysInMonth = () => {
return new Date(year, month + 1, 0).getDate(); return new Date(year, month + 1, 0).getDate();
...@@ -28,81 +40,50 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang ...@@ -28,81 +40,50 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang
const dayOfWeekNumber = getDayOfWeekNumber(i) const dayOfWeekNumber = getDayOfWeekNumber(i)
newDaysInMonth.push({dayNumber: i, dayOfWeek: getDayOfWeekString(dayOfWeekNumber)}) newDaysInMonth.push({dayNumber: i, dayOfWeek: getDayOfWeekString(dayOfWeekNumber)})
} }
setDaysInMonth(newDaysInMonth) setDaysInMonth(prevState=>newDaysInMonth)
}
const getTaskInDayCell = (tasks, day, hours) => {
const task = tasks.find(task=> {
if (year === task.infoForCell.startYear) {
if (month + 1 === task.infoForCell.startMonth) {
if (day.dayNumber === task.infoForCell.startDay && task.infoForCell.startDayOfWeek === day.dayOfWeek ) {
if ((task.infoForCell.endHour <= parseInt(hours.split(':')[0]) || task.infoForCell.startHour <= parseInt(hours.split(':')[0])) && (task.infoForCell.endHour > parseInt(hours.split(':')[0]))) {
return task
}
}
}
}
})
return task
} }
return ( return (
<> <>
<Grid <CalendarRow
container
align='center'
sx={{borderBottom: '1px solid black', borderRight: '1px solid black', borderLeft: '1px solid black'}}
> >
<Grid align='center' item xs={0.5} sx={{borderRight: '1px solid black'}}> <CalendarSmallCell xs={cellSizes.smallCell} />
{' '} <CalendarSmallCell xs={cellSizes.smallCell}/>
</Grid>
<Grid align='center' item xs={0.5} sx={{borderRight: '1px solid black'}}>
{' '}
</Grid>
{hoursInDay.map((hours, i)=>{ {hoursInDay.map((hours, i)=>{
return ( return (
<Grid key={i} item xs={1.2222} sx={{borderRight: '1px solid black'}}> <CalendarStandartCell key={i} xs={cellSizes.standarCell}>
{hours} {hours}
</Grid> </CalendarStandartCell>
) )
})} })}
</Grid> </CalendarRow>
{daysInMonth.map((day, i)=>{ {daysInMonth.map((day, i)=>{
return ( return (
<Grid <CalendarRow
key={i} key={i}
container
align='center'
sx={{borderBottom: '1px solid black', borderRight: '1px solid black', borderLeft: '1px solid black'}}
> >
<Grid align='center' item xs={0.5} sx={{borderRight: '1px solid black'}}> <CalendarSmallCell xs={cellSizes.smallCell}>{day.dayNumber}</CalendarSmallCell>
{day.dayNumber} <CalendarSmallCell xs={cellSizes.smallCell}>{day.dayOfWeek}</CalendarSmallCell>
</Grid>
<Grid align='center' item xs={0.5} sx={{borderRight: '1px solid black'}}>
{day.dayOfWeek}
</Grid>
{hoursInDay.map((hours, i)=>{ {hoursInDay.map((hours, i)=>{
const task = getTaskInDayCell(tasks, day, hours)
return ( return (
<Grid <CalendarStandartCell
key={i} key={i}
item xs={1.2222} item xs={cellSizes.standarCell}
sx={{borderRight: '1px solid black'}} onClick={()=>{createTaskInCellHandler(day.dayNumber, hours)}}
onClick={()=>{createTaskInCellHandler(day.dayNumber, hours)}}> >
{ task ? <CalendarTask
<Grid key={i} sx={{backgroundColor: 'lightgreen'}}> setCurrentTask={setCurrentTask}
<TextField onChange={(e)=>{onChangeCellTaskTitle(e)}}
id={task.title} year={year}
variant="standard" month={month}
value={task.title} tasks={tasks}
name='title' day={day}
onClick={(e)=>{e.stopPropagation(); setCurrentTask(task)}} hours={hours}
onChange={(e)=>{onChangeCellTaskTitle(e)}}></TextField> />
</Grid> : null} </CalendarStandartCell>
</Grid>
) )
})} })}
</Grid> </CalendarRow>
) )
})} })}
</> </>
......
import { Container } from '@mui/material'; import { Container } from '@mui/material';
import moment from 'moment';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import MonthCalendarBody from '../../components/MonthCalendarBody/MonthCalendarBody'; import MonthCalendarBody from '../../components/MonthCalendarBody/MonthCalendarBody';
...@@ -76,7 +75,7 @@ function MonthCalendar() { ...@@ -76,7 +75,7 @@ function MonthCalendar() {
const name = e.target.name; const name = e.target.name;
setCurrentTask({ ...currentTask, [name]: value }) setCurrentTask({ ...currentTask, [name]: value })
} }
console.log(tasks)
return ( return (
<> <>
<Container> <Container>
......
...@@ -18,15 +18,12 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -18,15 +18,12 @@ const tasksReduсer = (state = initialState, action) => {
const timeStart = task.dateTimeStart.split('T')[1] const timeStart = task.dateTimeStart.split('T')[1]
const timeEnd = task.dateTimeDue.split('T')[1] const timeEnd = task.dateTimeDue.split('T')[1]
const dayStart = parseInt(dateStart.split('-')[2]) const dayStart = parseInt(dateStart.split('-')[2])
const dayOfWeekStartNumber = new Date(new Date().getFullYear(), new Date().getMonth(), dayStart).getDay()
const dayOfWeekStartString = ["ВС","ПН","ВТ","СР","ЧТ","ПТ","СБ"][dayOfWeekStartNumber]
const monthStartNumber = parseInt(dateStart.split('-')[1]) const monthStartNumber = parseInt(dateStart.split('-')[1])
const yearStartNumber = parseInt(dateStart.split('-')[0]) const yearStartNumber = parseInt(dateStart.split('-')[0])
const timeStartHour = parseInt(timeStart.split(':')[0]) const timeStartHour = parseInt(timeStart.split(':')[0])
const timeEndHour = parseInt(timeEnd.split(':')[0]) const timeEndHour = parseInt(timeEnd.split(':')[0])
newArr.push({...task, infoForCell: { newArr.push({...task, infoForCell: {
startDay: dayStart, startDay: dayStart,
startDayOfWeek: dayOfWeekStartString,
startHour: timeStartHour, startHour: timeStartHour,
startMonth: monthStartNumber, startMonth: monthStartNumber,
startYear: yearStartNumber, startYear: yearStartNumber,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment