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

#131 Пофиксил баги с недельном календарем и реализовал драг энд дроп на задачи

parent e61c5e29
...@@ -42,6 +42,7 @@ const CalendarRowDay = ({ xs, hoursInDay, createTaskInCellHandler, currentTask, ...@@ -42,6 +42,7 @@ const CalendarRowDay = ({ xs, hoursInDay, createTaskInCellHandler, currentTask,
const tasks = getTasksWithInfoForPosition(line, hoursInDay, sortedTasks, i, rowDaySize.width) const tasks = getTasksWithInfoForPosition(line, hoursInDay, sortedTasks, i, rowDaySize.width)
return (<> return (<>
{tasks.map((task) => { {tasks.map((task) => {
const step = rowDaySize.width / hoursInDay.length
return ( return (
<CalendarTask <CalendarTask
key={task.task.id} key={task.task.id}
...@@ -56,6 +57,7 @@ const CalendarRowDay = ({ xs, hoursInDay, createTaskInCellHandler, currentTask, ...@@ -56,6 +57,7 @@ const CalendarRowDay = ({ xs, hoursInDay, createTaskInCellHandler, currentTask,
setCopyTask={setCopyTask} setCopyTask={setCopyTask}
dragTaskHandler={dragTaskHandler} dragTaskHandler={dragTaskHandler}
hourFormat={hourFormat} hourFormat={hourFormat}
step={step}
> >
</CalendarTask> </CalendarTask>
) )
......
import { Grid } from "@mui/material"; import { Grid } from "@mui/material";
import React, { memo, useMemo} from "react"; import React, { memo, useCallback, useMemo } from "react";
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
import { getColorTaskByPriority } from "../../../../../helpers/CalendarHelpers"; import { getColorTaskByPriority } from "../../../../../helpers/CalendarHelpers";
import CopyIcon from "../../../UI/CopyIcon/CopyIcon";
const CalendarTask = ({ setCurrentTask, handleOpen, task, setCopyTask, width, left, top, dragTaskHandler, hourFormat, step }) => {
const CalendarTask = ({ setCurrentTask, handleOpen, task, line, setCopyTask, width, left,top }) => {
const color = useMemo(() => { const color = useMemo(() => {
return getColorTaskByPriority(task.priority) return getColorTaskByPriority(task.priority)
}, [task.priority]) }, [task.priority])
const styles = { const styles = useMemo(()=>{
boxSizing: 'border-box', return {
backgroundColor: color, boxSizing: 'border-box',
height: `35px`, backgroundColor: color,
width: `${width - 10}px`, height: `35px`,
position: 'absolute', width: `${width - 10}px`,
display: 'flex', position: 'absolute',
left: left + 5, display: 'flex',
top: top, left: left + 5,
margin: '5px 5px 0 0', top: top,
padding: '5px', margin: '5px 5px 0 0',
textAlign: 'left', padding: '5px',
overflow: 'hidden', textAlign: 'left',
textOverflow: 'ellipsis', overflow: 'hidden',
borderRadius: '10px', textOverflow: 'ellipsis',
alignItems: 'center', borderRadius: '10px',
zIndex: '5', alignItems: 'center',
'&:hover': { zIndex: '5',
cursor: 'pointer', '&:hover': {
boxShadow: 'inset 0 0 100px 100px rgba(255, 255, 255, 0.3)' cursor: 'pointer',
}, boxShadow: 'inset 0 0 100px 100px rgba(255, 255, 255, 0.3)'
} },
}
const onClickTaskHandler = (e, task) => { }, [width, left, top, color])
const onClickTaskHandler = useCallback((e, task) => {
e.stopPropagation(); e.stopPropagation();
setCurrentTask((prevState) => { setCurrentTask((prevState) => {
return { return {
...@@ -49,42 +46,58 @@ const CalendarTask = ({ setCurrentTask, handleOpen, task, line, setCopyTask, wid ...@@ -49,42 +46,58 @@ const CalendarTask = ({ setCurrentTask, handleOpen, task, line, setCopyTask, wid
} }
}); });
handleOpen(e) handleOpen(e)
} },[handleOpen, setCurrentTask])
const dragLeaveHandler = (e) => { const dragLeaveHandler = useCallback((e) => {
e.target.style.boxShadow = 'none' e.target.style.boxShadow = 'none'
} },[])
const dragStartHandler = (e, line, task) => { const dragStartHandler = useCallback((e, task) => {
setCurrentTask(task); setCurrentTask(task);
} },[setCurrentTask])
const dragEndHandler = (e) => { const dragEndHandler = useCallback((e) => {
e.target.style.boxShadow = 'none' e.target.style.boxShadow = 'none'
} },[])
const onClickCopyIconHandler = (e) => { const onClickCopyIconHandler = useCallback((e) => {
e.stopPropagation(); e.stopPropagation();
setCopyTask(task) setCopyTask(task)
} },[task, setCopyTask])
const dragOverHandler = useCallback((e) => {
e.preventDefault();
},[])
const dropHandler = useCallback((e, task) => {
e.preventDefault();
let hour
if (hourFormat) {
hour = task.infoForCell.startHour + (Math.ceil(e.nativeEvent.offsetX / step) - 1)
} else {
hour = task.infoForCell.startHour + (Math.ceil(e.nativeEvent.offsetX / step) - 1 + Math.ceil(e.nativeEvent.offsetX / step) - 1)
}
dragTaskHandler(task.infoForCell.startDay, hour)
},[dragTaskHandler, hourFormat, step])
return (<> return (<>
<Grid <Grid
draggable={true} draggable={true}
onDragLeave={(e) => { dragLeaveHandler(e) }} onDragLeave={(e) => { dragLeaveHandler(e) }}
onDragStart={(e) => { dragStartHandler(e, line, task) }} onDragStart={(e) => { dragStartHandler(e, task) }}
onDragEnd={(e) => { dragEndHandler(e) }} onDragEnd={(e) => { dragEndHandler(e) }}
onDrop={(e) => { dropHandler(e, task) }}
onDragOver={(e) => { dragOverHandler(e) }}
sx={styles} sx={styles}
onClick={(e) => { onClickTaskHandler(e, task) }} onClick={(e) => { onClickTaskHandler(e, task) }}
> >
<span style={{ maxWidth: '60%', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}> <span style={{ maxWidth: '60%', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
{task.title} {task.title}
</span> </span>
<ContentCopyIcon sx={{ width: '20px', cursor: 'pointer', marginLeft: 'auto' }} onClick={(e) => { onClickCopyIconHandler(e) }}> <CopyIcon
</ContentCopyIcon> onClick={(e) => { onClickCopyIconHandler(e)}}
/>
</Grid> </Grid>
</>) </>)
}; };
......
...@@ -3,7 +3,7 @@ import { memo } from "react"; ...@@ -3,7 +3,7 @@ import { memo } from "react";
const CalendarSmallCell = ({ children, xs, week }) => { const CalendarSmallCell = ({ children, xs, week }) => {
return <> return <>
<Grid align='center' item xs={xs} sx={{ borderRight: week ? null : '1px solid black', height: week ? '40px' : null, borderBottom: week ? '1px solid black' : null, }}> <Grid align='center' item xs={xs} sx={{ borderRight: week ? null : '1px solid black', height: week ? '45px' : null, borderBottom: week ? '1px solid black' : null, }}>
{children} {children}
</Grid> </Grid>
</> </>
......
...@@ -2,13 +2,13 @@ import { Grid } from "@mui/material"; ...@@ -2,13 +2,13 @@ import { Grid } from "@mui/material";
import { memo, useEffect, useState } from "react"; import { memo, useEffect, useState } from "react";
import DefaultTask from "../DefaultTask/DefaultTask"; import DefaultTask from "../DefaultTask/DefaultTask";
const heightCell = 45 const heightCell = 40
const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCellHandler, handleOpen, modal, dragTaskHandler, linesInDay, week, copyTask, createCopyTask, month, year}) => { const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCellHandler, handleOpen, modal, dragTaskHandler, linesInDay, week, copyTask, createCopyTask, month, year }) => {
const [isThisCell, setIsThisCell] = useState(false) const [isThisCell, setIsThisCell] = useState(false)
const [top, setTop] = useState(0) const [top, setTop] = useState(0)
const cellClass = { const cellClass = {
position: 'relative', position: 'relative',
height: linesInDay?.length ? `${heightCell * linesInDay.length}px` : `${40}px`, height: linesInDay?.length ? `${heightCell * linesInDay.length + 5}px` : `${45}px`,
borderRight: '1px solid black', borderRight: '1px solid black',
borderBottom: week ? '1px solid black' : null, borderBottom: week ? '1px solid black' : null,
'&:hover': { '&:hover': {
...@@ -41,8 +41,11 @@ const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCell ...@@ -41,8 +41,11 @@ const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCell
const onClickHandler = (e) => { const onClickHandler = (e) => {
if (!week) { if (!week) {
console.log(e.nativeEvent.offsetY) if (e.nativeEvent.offsetY <= 5) {
setTop( 40 * Math.ceil((e.nativeEvent.offsetY - 5 * linesInDay.length)/40 - 1)) setTop(40 * Math.ceil((e.nativeEvent.offsetY) / 40 - 1))
} else {
setTop(40 * Math.ceil((e.nativeEvent.offsetY - 5) / 40 - 1))
}
} }
if (copyTask) { if (copyTask) {
createCopyTask(dayNumber, parseInt(hours.split(':')[0]), month, year) createCopyTask(dayNumber, parseInt(hours.split(':')[0]), month, year)
......
import React, { memo} from "react";
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
const styles = { width: '20px', cursor: 'pointer', marginLeft: 'auto' }
const CopyIcon = ({onClick}) => {
return (
<ContentCopyIcon sx={styles} onClick={onClick}>
</ContentCopyIcon>)
};
export default memo(CopyIcon);
\ No newline at end of file
...@@ -35,8 +35,6 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat ...@@ -35,8 +35,6 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
return getLinesInDay(availableTasks, sortedTasks, hoursInDay, hours, hourFormat) return getLinesInDay(availableTasks, sortedTasks, hoursInDay, hours, hourFormat)
}, [availableTasks, hourFormat, hours, hoursInDay, sortedTasks]) }, [availableTasks, hourFormat, hours, hoursInDay, sortedTasks])
console.log(month, year)
return (<> return (<>
<Grid item xs={12 / 7} ref={dayColumnRef} sx={{ position: 'relative' }}> <Grid item xs={12 / 7} ref={dayColumnRef} sx={{ position: 'relative' }}>
{linesInDay?.map((line, i) => { {linesInDay?.map((line, i) => {
......
import { Box } from "@mui/material" import { Box } from "@mui/material"
import { useEffect, useState, memo, useCallback, useMemo } from "react" import { useEffect, useState, memo, useCallback, useMemo } from "react"
import { getColorTaskByPriority } from "../../../../../../helpers/CalendarHelpers" import { getColorTaskByPriority } from "../../../../../../helpers/CalendarHelpers"
import ContentCopyIcon from '@mui/icons-material/ContentCopy'; import CopyIcon from "../../../../UI/CopyIcon/CopyIcon";
function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, setCurrentTask, modal, setCopyTask, month, dragTaskHandler, step, hourFormat}) { function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, setCurrentTask, modal, setCopyTask, month, dragTaskHandler, step, hourFormat}) {
...@@ -81,13 +81,18 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, ...@@ -81,13 +81,18 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen,
} else { } else {
hour = task.infoForCell.startHour + (Math.ceil(e.nativeEvent.offsetY/step)-1 + Math.ceil(e.nativeEvent.offsetY/step)-1) hour = task.infoForCell.startHour + (Math.ceil(e.nativeEvent.offsetY/step)-1 + Math.ceil(e.nativeEvent.offsetY/step)-1)
} }
dragTaskHandler(task.infoForCell.startDay, hour) dragTaskHandler(task.infoForCell.startDay, hour, task.infoForCell.startMonth - 1, task.infoForCell.startYear)
} }
const dragLeaveHandler = (e) => { const dragLeaveHandler = (e) => {
e.preventDefault(); e.preventDefault();
} }
const onClickCopyIconHandler = useCallback((e) => {
e.stopPropagation();
setCopyTask(task)
},[task, setCopyTask])
return ( return (
<Box <Box
draggable={true} draggable={true}
...@@ -102,8 +107,9 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, ...@@ -102,8 +107,9 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen,
<span style={{ textOverflow: 'ellipsis', padding: '5px 0 0 5px' }}> <span style={{ textOverflow: 'ellipsis', padding: '5px 0 0 5px' }}>
{task.title} {task.title}
</span> </span>
<ContentCopyIcon sx={{ marginLeft: 'auto', marginTop: '5px' }} onClick={(e) => { e.stopPropagation(); setCopyTask(task) }}> <CopyIcon
</ContentCopyIcon> onClick={(e) => { onClickCopyIconHandler(e)}}
/>
</Box>); </Box>);
} }
......
...@@ -172,7 +172,7 @@ function WeekCalendar() { ...@@ -172,7 +172,7 @@ function WeekCalendar() {
const timeStartHour = currentTask.infoForCell.startHour const timeStartHour = currentTask.infoForCell.startHour
const month = currentTask.infoForCell.month const month = currentTask.infoForCell.month
const day = currentTask.infoForCell.startDay const day = currentTask.infoForCell.startDay
const year = currentTask.infoForCell.year const year = currentTask.infoForCell.startYear
const due = dateToISOLikeButLocal(new Date(year, month, day, timeEndHour - 1, 59)) const due = dateToISOLikeButLocal(new Date(year, month, day, timeEndHour - 1, 59))
const start = dateToISOLikeButLocal(new Date(year, month, day, timeStartHour, 0)) const start = dateToISOLikeButLocal(new Date(year, month, day, timeStartHour, 0))
if (currentTask.id) { if (currentTask.id) {
......
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