Commit 211d3f21 authored by Ermolaev Timur's avatar Ermolaev Timur

#56 Завершил drag and drop

parent c90e117a
import { Grid } from "@mui/material"; import { Grid } from "@mui/material";
import { memo, useMemo, useState } from "react"; import { memo, useEffect, useMemo, useState } from "react";
import { useDispatch } from "react-redux";
import CalendarStandartCell from "../CalendarStandartCell.js/CalendarStandartCell"; import CalendarStandartCell from "../CalendarStandartCell.js/CalendarStandartCell";
import CalendarTask from "../CalendarTask/CalendarTask"; import CalendarTask from "../CalendarTask/CalendarTask";
import EmptyBox from "./EmptyBox/EmptyBox";
const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, handleOpen, modal, setCurrentTask, year, month, tasks, day, hourFormat, setCurrentLine, currentLine, dragTaskHandler}) => { const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, handleOpen, modal, setCurrentTask, year, month, tasks, day, hourFormat, setCurrentLine, currentLine, dragTaskHandler}) => {
const hours = useMemo(()=>{ const hours = useMemo(()=>{
return hoursInDay.map((hour)=>parseInt(hour.split(':')[0]))}, return hoursInDay.map((hour)=>parseInt(hour.split(':')[0]))},
[hoursInDay]) [hoursInDay])
...@@ -44,6 +45,7 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h ...@@ -44,6 +45,7 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h
hourDiff = 2 hourDiff = 2
hourDiffEnd = 1 hourDiffEnd = 1
} }
if (availableTasks.length) { if (availableTasks.length) {
lines.push(hoursInDay.map((hour)=>parseInt(hour.split(':')[0]))) lines.push(hoursInDay.map((hour)=>parseInt(hour.split(':')[0])))
for (let k = 0; k < sortedTasks.length; k++) { for (let k = 0; k < sortedTasks.length; k++) {
...@@ -73,11 +75,15 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h ...@@ -73,11 +75,15 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h
} }
} }
if (!havePlace) { if (!havePlace) {
if (j + 1 === lines.length) {
lines.push(hoursInDay.map((hour)=>parseInt(hour.split(':')[0])))
}
havePlace = true havePlace = true
break; break;
} }
line[i] += `-${k}` line[i] += `-${k}`
if ((task.infoForCell.endMinute === 59 && task.infoForCell.endHour === hour + hourDiffEnd) || (!hourFormat && task.infoForCell.endMinute === 59 && task.infoForCell.endHour === hour)) { if ((task.infoForCell.endMinute === 59 && task.infoForCell.endHour === hour + hourDiffEnd)
|| (!hourFormat && task.infoForCell.endMinute === 59 && task.infoForCell.endHour === hour)) {
skipLine = true skipLine = true
break; break;
} }
...@@ -114,7 +120,9 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h ...@@ -114,7 +120,9 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h
if (taskIsThere) { if (taskIsThere) {
taskIsThere.xs +=xs taskIsThere.xs +=xs
} else { } else {
boxes.push({xs: xs, task: sortedTasks[line[i].split('-')[1]]}) boxes.push({
xs: xs,
task: sortedTasks[line[i].split('-')[1]]})
} }
} }
} }
...@@ -122,16 +130,6 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h ...@@ -122,16 +130,6 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h
} }
} }
const dragOverHandler = (e) => {
e.preventDefault();
}
const dropHandler = (e, currentHour) => {
e.stopPropagation()
e.preventDefault();
dragTaskHandler(day.dayNumber, currentHour)
}
return <> return <>
<Grid <Grid
container container
...@@ -165,11 +163,10 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h ...@@ -165,11 +163,10 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h
{boxes.map((box, index)=>{ {boxes.map((box, index)=>{
if (box.task) { if (box.task) {
return (<Grid return (<Grid
key={i}
item xs={box.xs} item xs={box.xs}
sx={{height: '35px', marginBottom: '5px'}} sx={{height: '35px', marginBottom: '5px'}}
onDragOver={(e)=>{dragOverHandler(e)}} >
onDrop={(e)=>{dropHandler(e, parseInt(hours[index]))}
}>
<CalendarTask <CalendarTask
dragTaskHandler={dragTaskHandler} dragTaskHandler={dragTaskHandler}
setCurrentLine={()=>{setCurrentLine(day.dayNumber)}} setCurrentLine={()=>{setCurrentLine(day.dayNumber)}}
...@@ -183,16 +180,38 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h ...@@ -183,16 +180,38 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h
/> />
</Grid>) </Grid>)
} else { } else {
return (<Grid return (<EmptyBox
onDragOver={(e)=>{dragOverHandler(e)}} key={i}
onDrop={(e)=>{dropHandler(e, box.hour)}} modal={modal}
item xs={box.xs} sx={{height: '35px', backgroundColor: 'rgb(0,0,0,0)'}}> dayNumber={day.dayNumber}
hourNumber={box.hour}
</Grid>) handleOpen={handleOpen}
dragTaskHandler={dragTaskHandler}
createTaskInCellHandler={createTaskInCellHandler}
xs={box.xs}
>
</EmptyBox>)
} }
})} })}
</Grid>) </Grid>)
})} })}
<Grid container sx={{height: '35px', backgroundColor: 'rgb(0,0,0,0)', marginBottom: '5px'}}>
{hoursInDay.map((hour, i)=>{
const hourNumber = parseInt(hour)
return(<EmptyBox
key={i}
modal={modal}
dayNumber={day.dayNumber}
hourNumber={hourNumber}
handleOpen={handleOpen}
dragTaskHandler={dragTaskHandler}
createTaskInCellHandler={createTaskInCellHandler}
xs={xs}
>
</EmptyBox>)
})}
</Grid>
</Grid> </Grid>
</> </>
}; };
......
import { Grid} from "@mui/material";
import React, { memo, useEffect, useState} from "react";
import DefaultTask from "../../DefaultTask/DefaultTask";
const EmptyBox = ({hourNumber, handleOpen, dayNumber, xs, dragTaskHandler, modal, createTaskInCellHandler}) => {
const [isThisCell, setIsThisCell] = useState(false)
useEffect(()=>{
if(!modal) {
setIsThisCell(false);
}
}, [modal])
const onClickHandler = (e, dayNumber, hour) => {
createTaskInCellHandler(dayNumber, hour);
setIsThisCell(true);
handleOpen(e)
}
const dragOverHandler = (e) => {
e.preventDefault();
}
const dropHandler = (e) => {
e.stopPropagation()
e.preventDefault();
dragTaskHandler(dayNumber, hourNumber)
}
return(<Grid
onDragOver={(e)=>{dragOverHandler(e)}}
onDrop={(e)=>{dropHandler(e)}}
onClick={(e)=>{onClickHandler(e, dayNumber, hourNumber)}}
item xs={xs} sx={{height: '35px', backgroundColor: 'rgb(0,0,0,0)'}}>
{isThisCell ?
<DefaultTask/> : null}
</Grid>)
};
export default memo(EmptyBox, (prevProps, nextProps)=>{
if(!prevProps.modal) return false
if(nextProps.modal) return true
});
\ No newline at end of file
...@@ -23,10 +23,6 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, c ...@@ -23,10 +23,6 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, c
handleOpen(e) handleOpen(e)
} }
const dragOverHandler = (e) => {
e.preventDefault();
e.target.style.boxShadow = '0 4px 3px grey'
}
const dragLeaveHandler = (e) => { const dragLeaveHandler = (e) => {
e.target.style.boxShadow = 'none' e.target.style.boxShadow = 'none'
} }
...@@ -37,21 +33,14 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, c ...@@ -37,21 +33,14 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, c
const dragEndHandler = (e) => { const dragEndHandler = (e) => {
e.target.style.boxShadow = 'none' e.target.style.boxShadow = 'none'
} }
const dropHandler = (e, line, task) => {
e.stopPropagation()
e.preventDefault();
console.log(hour)
dragTaskHandler(line, hour)
}
return (<> return (<>
<Grid <Grid
draggable={true} draggable={true}
onDragOver={(e)=>{dragOverHandler(e)}}
onDragLeave={(e)=>{dragLeaveHandler(e)}} onDragLeave={(e)=>{dragLeaveHandler(e)}}
onDragStart={(e)=>{dragStartHandler(e, line, task)}} onDragStart={(e)=>{dragStartHandler(e, line, task)}}
onDragEnd={(e)=>{dragEndHandler(e)}} onDragEnd={(e)=>{dragEndHandler(e)}}
onDrop={(e)=>{dropHandler(e, line, task)}}
sx={{ position: 'relative', height: '30px', backgroundColor: color, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', borderRadius: '10px', margin: '5px 10px', display: 'flex', justifyContent: 'flex-start', alignItems: 'center', paddingLeft: '5px', zIndex: '5'}} sx={{ position: 'relative', height: '30px', backgroundColor: color, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', borderRadius: '10px', margin: '5px 10px', display: 'flex', justifyContent: 'flex-start', alignItems: 'center', paddingLeft: '5px', zIndex: '5'}}
onClick={(e)=>{onClickTaskHandler(e, task)}} onClick={(e)=>{onClickTaskHandler(e, task)}}
> >
......
import { Box } from "@mui/material";
import { memo } from "react";
const DefaultTask = ({}) => {
return (<>
<Box
sx={{ position: 'relative', height: '30px', backgroundColor: 'lightgreen', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', borderRadius: '10px', margin: '5px 10px', display: 'flex', justifyContent: 'flex-start', alignItems: 'center', paddingLeft: '5px', zIndex: '5'}}
>
<span>
Задача
</span>
</Box>
</>)
};
export default memo(DefaultTask);
\ No newline at end of file
...@@ -13,7 +13,6 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, current ...@@ -13,7 +13,6 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, current
const [currentLine, setCurrentLine] = useState('') const [currentLine, setCurrentLine] = useState('')
const [modal, setModal] = useState({open:false, y: 0, x: 0,}); const [modal, setModal] = useState({open:false, y: 0, x: 0,});
const handleOpen = (e) => { const handleOpen = (e) => {
console.log(e)
setModal( { setModal( {
open: true, open: true,
yPage: e.clientY, yPage: e.clientY,
......
...@@ -103,7 +103,12 @@ function MonthCalendar() { ...@@ -103,7 +103,12 @@ function MonthCalendar() {
} }
const createTaskInCellHandler = (dayNumber, dayHour) => { const createTaskInCellHandler = (dayNumber, dayHour) => {
const hour = parseInt(dayHour.split(':')[0]) let hour
if (!isNaN(dayHour)) {
hour = dayHour
} else {
hour = parseInt(dayHour.split(':')[0])
}
let hourDue let hourDue
if (hourFormat) { if (hourFormat) {
hourDue = hour + 0 hourDue = hour + 0
...@@ -119,9 +124,8 @@ function MonthCalendar() { ...@@ -119,9 +124,8 @@ function MonthCalendar() {
} }
setCurrentTask((newTask)) setCurrentTask((newTask))
} }
const dragTaskHandler = async (dayNumber, hour) => { const dragTaskHandler = async (dayNumber, hour) => {
console.log(dayNumber, hour)
const timeEnd = currentTask.dateTimeDue.split('T')[1] const timeEnd = currentTask.dateTimeDue.split('T')[1]
const timeEndHour = parseInt(timeEnd.split(':')[0]) const timeEndHour = parseInt(timeEnd.split(':')[0])
const timeStart = currentTask.dateTimeStart.split('T')[1] const timeStart = currentTask.dateTimeStart.split('T')[1]
...@@ -134,6 +138,7 @@ function MonthCalendar() { ...@@ -134,6 +138,7 @@ function MonthCalendar() {
dateTimeStart: start, dateTimeStart: start,
dateTimeDue: due dateTimeDue: due
})) }))
setCurrentTask({})
} }
const sendNewTaskHandler = async () => { const sendNewTaskHandler = async () => {
......
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