Commit 213b15cc authored by Ermolaev Timur's avatar Ermolaev Timur

#54 Реализовал изменение размера задачи через кнопки

parent 7f789605
import { Grid} from "@mui/material"; import { Grid} from "@mui/material";
import React, { memo, useEffect, useRef, useState} from "react"; import React, { memo, useEffect, useRef, useState} from "react";
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import ArrowForwardIcon from '@mui/icons-material/ArrowForward';
const arrowClass = {
height: '20px',
cursor: 'pointer',
transition: '0.5s',
"&:hover": {
transition: '0.5s',
transform: 'scale(1.2)'
}
}
const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, increaseTaskHandler, reduceTaskHandler}) => { const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, increaseTaskHandler, reduceTaskHandler}) => {
...@@ -15,80 +26,6 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, i ...@@ -15,80 +26,6 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, i
} }
}, [task]) }, [task])
const ref = useRef(null);
const refLeft = useRef(null);
const refRight = useRef(null);
useEffect(() => {
const resizeableEle = ref.current;
const styles = window.getComputedStyle(resizeableEle);
let width = parseInt(styles.width, 10);
let x = 0;
const lastPoint = {x: null, y: null}
const onMouseMoveRightResize = (event) => {
event.stopPropagation()
const leftOrRight = (
event.clientX > lastPoint.x ? 'right'
: event.clientX < lastPoint.x ? 'left'
: 'none'
)
if (leftOrRight === 'right') {
increaseTaskHandler(line, task, false)
}
lastPoint.x = event.clientX
lastPoint.y = event.clientY
};
const onMouseUpRightResize = (event) => {
event.stopPropagation()
document.removeEventListener("mousemove", onMouseMoveRightResize);
};
const onMouseDownRightResize = (event) => {
event.stopPropagation()
x = event.clientX;
resizeableEle.style.left = styles.left;
resizeableEle.style.right = null;
document.addEventListener("mousemove", onMouseMoveRightResize);
document.addEventListener("mouseup", onMouseUpRightResize);
};
// Left resize
const onMouseMoveLeftResize = (event) => {
event.stopPropagation()
const dx = event.clientX - x;
x = event.clientX;
width = width - dx;
resizeableEle.style.width = `${width}px`;
};
const onMouseUpLeftResize = (event) => {
event.stopPropagation()
document.removeEventListener("mousemove", onMouseMoveLeftResize);
};
const onMouseDownLeftResize = (event) => {
event.stopPropagation()
x = event.clientX;
resizeableEle.style.right = styles.right;
resizeableEle.style.left = null;
document.addEventListener("mousemove", onMouseMoveLeftResize);
document.addEventListener("mouseup", onMouseUpLeftResize);
};
// Add mouse down event listener
const resizerRight = refRight.current;
resizerRight.addEventListener("mousedown", onMouseDownRightResize);
const resizerLeft = refLeft.current;
resizerLeft.addEventListener("mousedown", onMouseDownLeftResize);
return () => {
resizerRight.removeEventListener("mousedown", onMouseDownRightResize);
resizerLeft.removeEventListener("mousedown", onMouseDownLeftResize);
};
}, []);
const onClickTaskHandler = (e, task) => { const onClickTaskHandler = (e, task) => {
e.stopPropagation(); e.stopPropagation();
setCurrentTask(task); setCurrentTask(task);
...@@ -109,18 +46,23 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, i ...@@ -109,18 +46,23 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, i
return (<> return (<>
<Grid <Grid
draggable={true} draggable={true}
ref={ref}
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)}}
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', justifyContent: 'space-between'}}
onClick={(e)=>{onClickTaskHandler(e, task)}} onClick={(e)=>{onClickTaskHandler(e, task)}}
> >
<div ref={refLeft} style={{cursor: 'col-resize',height: '100%', left: '0',top: '0', width: '5px', backgroundColor: 'grey'}}></div> <div style={{display: 'flex', alignItems: 'center'}}>
<span> <ArrowBackIcon sx={arrowClass} onClick={(e)=>{e.stopPropagation(); increaseTaskHandler(line, task, true)}}/>
{task.title} <ArrowForwardIcon sx={arrowClass} onClick={(e)=>{e.stopPropagation(); reduceTaskHandler(line, task, true)}}/>
</span> </div>
<div ref={refRight} style={{cursor: 'col-resize',height: '100%', right: '0',top: '0', width: '5px', backgroundColor: 'grey'}}></div> <span>
{task.title}
</span>
<div style={{display: 'flex', alignItems: 'center'}}>
<ArrowBackIcon sx={arrowClass} onClick={(e)=>{e.stopPropagation(); reduceTaskHandler(line, task, false)}}/>
<ArrowForwardIcon sx={arrowClass} onClick={(e)=>{e.stopPropagation(); increaseTaskHandler(line, task, false)}}/>
</div>
</Grid> </Grid>
</>) </>)
}; };
......
...@@ -154,10 +154,10 @@ function MonthCalendar() { ...@@ -154,10 +154,10 @@ function MonthCalendar() {
hourDiff = 2 hourDiff = 2
} }
let due let due
let start let start
if (isStartTask) { if (isStartTask) {
due = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeEndHour, 59)) due = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeEndHour, 59))
start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeStartHour + hourDiff, 0)) start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeStartHour - hourDiff, 0))
} else { } else {
due = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeEndHour + hourDiff, 59)) due = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeEndHour + hourDiff, 59))
start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeStartHour, 0)) start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeStartHour, 0))
...@@ -170,6 +170,7 @@ function MonthCalendar() { ...@@ -170,6 +170,7 @@ function MonthCalendar() {
delete newObj.infoForCell delete newObj.infoForCell
await dispatch(editTask(newObj)) await dispatch(editTask(newObj))
setCurrentTask({}) setCurrentTask({})
} }
const reduceTaskHandler = async (dayNumber, task, isStartTask) => { const reduceTaskHandler = async (dayNumber, task, isStartTask) => {
...@@ -178,28 +179,33 @@ function MonthCalendar() { ...@@ -178,28 +179,33 @@ function MonthCalendar() {
const timeStart = task.dateTimeStart.split('T')[1] const timeStart = task.dateTimeStart.split('T')[1]
const timeStartHour = parseInt(timeStart.split(':')[0]) const timeStartHour = parseInt(timeStart.split(':')[0])
let hourDiff let hourDiff
let hourDiffCheck
if (hourFormat) { if (hourFormat) {
hourDiff = 1 hourDiff = 1
hourDiffCheck = 0
} else { } else {
hourDiff = 2 hourDiff = 2
hourDiffCheck = 1
} }
let due let due
let start let start
if (isStartTask) { if (task.infoForCell.endHour - task.infoForCell.startHour - hourDiffCheck !== 0) {
due = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeEndHour, 59)) if (isStartTask) {
start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeStartHour - hourDiff, 0)) due = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeEndHour, 59))
} else { start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeStartHour + hourDiff, 0))
due = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeEndHour - hourDiff, 59)) } else {
start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeStartHour, 0)) due = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeEndHour - hourDiff, 59))
} start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeStartHour, 0))
const newObj = { }
...task, const newObj = {
dateTimeStart: start, ...task,
dateTimeDue: due dateTimeStart: start,
dateTimeDue: due
}
delete newObj.infoForCell
await dispatch(editTask(newObj))
setCurrentTask({})
} }
delete newObj.infoForCell
await dispatch(editTask(newObj))
setCurrentTask({})
} }
const sendNewTaskHandler = async () => { const sendNewTaskHandler = async () => {
......
...@@ -32,7 +32,8 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -32,7 +32,8 @@ const tasksReduсer = (state = initialState, action) => {
const newArr = [] const newArr = []
action.tasks.forEach((task)=>{ action.tasks.forEach((task)=>{
if (task.dateTimeStart && task.dateTimeDue) { if (task.dateTimeStart && task.dateTimeDue) {
if (new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() < (10 * 3600000)) { if (new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() < (24 * 3600000) &&
new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() > 0) {
const dateStart = task.dateTimeStart.split('T')[0] const dateStart = task.dateTimeStart.split('T')[0]
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]
......
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