Commit 7f789605 authored by Ermolaev Timur's avatar Ermolaev Timur

#54 Реализовал увелечение задачи

parent 812e601b
...@@ -4,7 +4,7 @@ import CalendarStandartCell from "../CalendarStandartCell.js/CalendarStandartCel ...@@ -4,7 +4,7 @@ import CalendarStandartCell from "../CalendarStandartCell.js/CalendarStandartCel
import CalendarTask from "../CalendarTask/CalendarTask"; import CalendarTask from "../CalendarTask/CalendarTask";
import EmptyBox from "./EmptyBox/EmptyBox"; 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, increaseTaskHandler, reduceTaskHandler}) => {
const hours = useMemo(()=>{ const hours = useMemo(()=>{
return hoursInDay.map((hour)=>parseInt(hour.split(':')[0]))}, return hoursInDay.map((hour)=>parseInt(hour.split(':')[0]))},
...@@ -163,7 +163,6 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h ...@@ -163,7 +163,6 @@ 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'}}
> >
...@@ -177,11 +176,12 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h ...@@ -177,11 +176,12 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h
task={box.task} task={box.task}
setCurrentTask={setCurrentTask} setCurrentTask={setCurrentTask}
handleOpen={handleOpen} handleOpen={handleOpen}
increaseTaskHandler={increaseTaskHandler}
reduceTaskHandler={reduceTaskHandler}
/> />
</Grid>) </Grid>)
} else { } else {
return (<EmptyBox return (<EmptyBox
key={i}
modal={modal} modal={modal}
dayNumber={day.dayNumber} dayNumber={day.dayNumber}
hourNumber={box.hour} hourNumber={box.hour}
......
import { Grid} from "@mui/material"; import { Grid} from "@mui/material";
import React, { memo, useEffect, useRef} from "react"; import React, { memo, useEffect, useRef, useState} from "react";
const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, currentLine, currentTask, dragTaskHandler, hour}) => { const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, increaseTaskHandler, reduceTaskHandler}) => {
const [color, setColor] = useState('') const [color, setColor] = useState('')
useEffect(() => { useEffect(() => {
...@@ -25,19 +25,28 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, c ...@@ -25,19 +25,28 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, c
let width = parseInt(styles.width, 10); let width = parseInt(styles.width, 10);
let x = 0; let x = 0;
// Right resize const lastPoint = {x: null, y: null}
const onMouseMoveRightResize = (event) => { const onMouseMoveRightResize = (event) => {
const dx = event.clientX - x; event.stopPropagation()
x = event.clientX; const leftOrRight = (
width = width + dx; event.clientX > lastPoint.x ? 'right'
resizeableEle.style.width = `${width}px`; : event.clientX < lastPoint.x ? 'left'
: 'none'
)
if (leftOrRight === 'right') {
increaseTaskHandler(line, task, false)
}
lastPoint.x = event.clientX
lastPoint.y = event.clientY
}; };
const onMouseUpRightResize = (event) => { const onMouseUpRightResize = (event) => {
event.stopPropagation()
document.removeEventListener("mousemove", onMouseMoveRightResize); document.removeEventListener("mousemove", onMouseMoveRightResize);
}; };
const onMouseDownRightResize = (event) => { const onMouseDownRightResize = (event) => {
event.stopPropagation()
x = event.clientX; x = event.clientX;
resizeableEle.style.left = styles.left; resizeableEle.style.left = styles.left;
resizeableEle.style.right = null; resizeableEle.style.right = null;
...@@ -47,6 +56,7 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, c ...@@ -47,6 +56,7 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, c
// Left resize // Left resize
const onMouseMoveLeftResize = (event) => { const onMouseMoveLeftResize = (event) => {
event.stopPropagation()
const dx = event.clientX - x; const dx = event.clientX - x;
x = event.clientX; x = event.clientX;
width = width - dx; width = width - dx;
...@@ -54,10 +64,12 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, c ...@@ -54,10 +64,12 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, c
}; };
const onMouseUpLeftResize = (event) => { const onMouseUpLeftResize = (event) => {
event.stopPropagation()
document.removeEventListener("mousemove", onMouseMoveLeftResize); document.removeEventListener("mousemove", onMouseMoveLeftResize);
}; };
const onMouseDownLeftResize = (event) => { const onMouseDownLeftResize = (event) => {
event.stopPropagation()
x = event.clientX; x = event.clientX;
resizeableEle.style.right = styles.right; resizeableEle.style.right = styles.right;
resizeableEle.style.left = null; resizeableEle.style.left = null;
......
...@@ -8,7 +8,7 @@ import MonthCalendarModalContent from "../MonthCalendarModalContent/MonthCalenda ...@@ -8,7 +8,7 @@ import MonthCalendarModalContent from "../MonthCalendarModalContent/MonthCalenda
import CalendarRowDay from "./CalendarRowDay/CalendarRowDay"; import CalendarRowDay from "./CalendarRowDay/CalendarRowDay";
function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, currentTask, setCurrentTask, hourFormat, setHourFormat, onChangeCurrentTaskHandler, sendNewTaskHandler, deleteTaskHandler, cellSizes, hoursInDay, daysInMonth, dragTaskHandler}) { function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, currentTask, setCurrentTask, hourFormat, setHourFormat, onChangeCurrentTaskHandler, sendNewTaskHandler, deleteTaskHandler, cellSizes, hoursInDay, daysInMonth, dragTaskHandler, increaseTaskHandler, reduceTaskHandler}) {
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,});
...@@ -83,6 +83,8 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, current ...@@ -83,6 +83,8 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, current
tasks={tasks} tasks={tasks}
day={day} day={day}
hourFormat={hourFormat} hourFormat={hourFormat}
increaseTaskHandler={increaseTaskHandler}
reduceTaskHandler={reduceTaskHandler}
> >
</CalendarRowDay> </CalendarRowDay>
</CalendarRow> </CalendarRow>
......
...@@ -133,11 +133,72 @@ function MonthCalendar() { ...@@ -133,11 +133,72 @@ function MonthCalendar() {
const hourDiff = timeEndHour - timeStartHour const hourDiff = timeEndHour - timeStartHour
const due = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, hour + hourDiff, 59)) const due = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, hour + hourDiff, 59))
const start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, hour, 0)) const start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, hour, 0))
await dispatch(editTask({ const newObj = {
...currentTask, ...currentTask,
dateTimeStart: start, dateTimeStart: start,
dateTimeDue: due dateTimeDue: due
})) }
delete newObj.infoForCell
await dispatch(editTask(newObj))
setCurrentTask({})
}
const increaseTaskHandler = async (dayNumber, task, isStartTask) => {
const timeEnd = task.dateTimeDue.split('T')[1]
const timeEndHour = parseInt(timeEnd.split(':')[0])
const timeStart = task.dateTimeStart.split('T')[1]
const timeStartHour = parseInt(timeStart.split(':')[0])
let hourDiff
if (hourFormat) {
hourDiff = 1
} else {
hourDiff = 2
}
let due
let start
if (isStartTask) {
due = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeEndHour, 59))
start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeStartHour + hourDiff, 0))
} else {
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,
dateTimeStart: start,
dateTimeDue: due
}
delete newObj.infoForCell
await dispatch(editTask(newObj))
setCurrentTask({})
}
const reduceTaskHandler = async (dayNumber, task, isStartTask) => {
const timeEnd = task.dateTimeDue.split('T')[1]
const timeEndHour = parseInt(timeEnd.split(':')[0])
const timeStart = task.dateTimeStart.split('T')[1]
const timeStartHour = parseInt(timeStart.split(':')[0])
let hourDiff
if (hourFormat) {
hourDiff = 1
} else {
hourDiff = 2
}
let due
let start
if (isStartTask) {
due = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeEndHour, 59))
start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, timeStartHour - hourDiff, 0))
} else {
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,
dateTimeStart: start,
dateTimeDue: due
}
delete newObj.infoForCell
await dispatch(editTask(newObj))
setCurrentTask({}) setCurrentTask({})
} }
...@@ -193,6 +254,8 @@ function MonthCalendar() { ...@@ -193,6 +254,8 @@ function MonthCalendar() {
hoursInDay={hoursInDay} hoursInDay={hoursInDay}
daysInMonth={daysInMonth} daysInMonth={daysInMonth}
dragTaskHandler={dragTaskHandler} dragTaskHandler={dragTaskHandler}
increaseTaskHandler={increaseTaskHandler}
reduceTaskHandler={reduceTaskHandler}
/> />
</> </>
......
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