Commit 9388b278 authored by Ermolaev Timur's avatar Ermolaev Timur

#29 Реализовал отображение задач на 1 и 2 часах, а так же если в одной клетке 2 задачи

parent 8d1eb887
import { Grid, TextField } from "@mui/material"; import { Grid, TextField } from "@mui/material";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
const CalendarTask = ({year, month, tasks, day, hours, setCurrentTask, onChange}) => { const CalendarTask = ({year, month, tasks, day, hours, setCurrentTask, onChange, hourFormat}) => {
const getTaskInDayCell = (tasks, day, hours) => { const getTaskInDayCell = (tasks, day, hours) => {
const task = tasks.find(task=> { const hour = parseInt(hours.split(':')[0])
let hourDiffEnd
let hourDiffStart
if (hourFormat) {
hourDiffEnd = hour + 1
} else {
hourDiffEnd = hour + 2
}
if (hourFormat) {
hourDiffStart = hour - 1
} else {
hourDiffStart = hour - 2
}
const tasksCell = tasks.filter(task=> {
if (year === task.infoForCell.startYear) { if (year === task.infoForCell.startYear) {
if (month + 1 === task.infoForCell.startMonth) { if (month + 1 === task.infoForCell.startMonth) {
if (day.dayNumber === task.infoForCell.startDay) { 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]))) { if (((task.infoForCell.endHour <= hour || task.infoForCell.startHour <= hour) && (task.infoForCell.endHour > hour))
return task || (task.infoForCell.startHour >= hour && task.infoForCell.endHour < hourDiffEnd)
|| (task.infoForCell.endMinute === 59 && task.infoForCell.endHour === hour)) {
return task
} }
} }
} }
} }
}) })
return task return tasksCell
} }
let task = getTaskInDayCell(tasks, day, hours)
return (<> const tasksCell = getTaskInDayCell(tasks, day, hours)
{task ?
<Grid sx={{backgroundColor: 'lightgreen'}}> const renderTasks = (tasksCell) => {
tasksCell.map((task, i)=>{
return (
<Grid key={task.id} sx={{backgroundColor: 'lightgreen'}}>
<TextField <TextField
id={task.title} id={task.title}
variant="standard" variant="standard"
...@@ -32,7 +48,26 @@ const CalendarTask = ({year, month, tasks, day, hours, setCurrentTask, onChange} ...@@ -32,7 +48,26 @@ const CalendarTask = ({year, month, tasks, day, hours, setCurrentTask, onChange}
onChange={onChange}> onChange={onChange}>
</TextField> </TextField>
</Grid> </Grid>
: null } )
})}
console.log(tasksCell[0])
return (<>
{tasksCell.length ? tasksCell.map((task, i)=>
{
return (
<Grid key={task.id} 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 }
</>) </>)
}; };
......
...@@ -20,7 +20,7 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang ...@@ -20,7 +20,7 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang
useEffect(()=>{ useEffect(()=>{
if (hourFormat) { if (hourFormat) {
const arr = ['8:00', '9:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '17:00', '18:00', '19:00','20:00','21:00','22:00', '23:00', '7:00'] const arr = ['8:00', '9:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00','20:00','21:00','22:00', '00:00', '7:00']
const cells = arr.length const cells = arr.length
const xs = 10.8/cells const xs = 10.8/cells
setCellSizes(()=>{ setCellSizes(()=>{
...@@ -28,7 +28,7 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang ...@@ -28,7 +28,7 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang
}) })
setHoursInDay(()=>arr) setHoursInDay(()=>arr)
} else { } else {
const arr = ['8:00', '10:00', '12:00', '14:00', '16:00', '18:00', '20:00', '22:00', '24:00', '7:00'] const arr = ['8:00', '10:00', '12:00', '14:00', '16:00', '18:00', '20:00', '22:00', '00:00', '7:00']
const cells = arr.length const cells = arr.length
const xs = 10.8/cells const xs = 10.8/cells
setCellSizes(()=>{ setCellSizes(()=>{
...@@ -104,6 +104,7 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang ...@@ -104,6 +104,7 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang
tasks={tasks} tasks={tasks}
day={day} day={day}
hours={hours} hours={hours}
hourFormat={hourFormat}
/> />
</CalendarStandartCell> </CalendarStandartCell>
) )
......
...@@ -66,15 +66,15 @@ function MonthCalendar() { ...@@ -66,15 +66,15 @@ function MonthCalendar() {
const hour = parseInt(dayHour.split(':')[0]) const hour = parseInt(dayHour.split(':')[0])
let hourDue let hourDue
if (hourFormat) { if (hourFormat) {
hourDue = hour + 1 hourDue = hour + 0
} else { } else {
hourDue = hour + 2 hourDue = hour + 1
} }
const newTask = { const newTask = {
title:"Задача", title:"Задача",
description:"описание", description:"описание",
dateTimeStart: dateToISOLikeButLocal(new Date(year, month, dayNumber, hour)), dateTimeStart: dateToISOLikeButLocal(new Date(year, month, dayNumber, hour, 0)),
dateTimeDue: dateToISOLikeButLocal(new Date(year, month, dayNumber, hourDue)), dateTimeDue: dateToISOLikeButLocal(new Date(year, month, dayNumber, hourDue, 59)),
} }
console.log(newTask) console.log(newTask)
dispatch(addTask(newTask)) dispatch(addTask(newTask))
......
...@@ -22,12 +22,16 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -22,12 +22,16 @@ const tasksReduсer = (state = initialState, action) => {
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])
const timeStartMinute = parseInt(timeStart.split(':')[1])
const timeEndMinute = parseInt(timeEnd.split(':')[1])
newArr.push({...task, infoForCell: { newArr.push({...task, infoForCell: {
startDay: dayStart, startDay: dayStart,
startHour: timeStartHour, startHour: timeStartHour,
startMonth: monthStartNumber, startMonth: monthStartNumber,
startYear: yearStartNumber, startYear: yearStartNumber,
startMinute: timeStartMinute,
endHour: timeEndHour, endHour: timeEndHour,
endMinute: timeEndMinute,
} }
} ) } )
} }
......
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