Commit 6b4eb850 authored by Ermolaev Timur's avatar Ermolaev Timur

#111 Чуть исправил логику, реализовал создание задачи

parent 989e9d5d
import { Grid } from "@mui/material"; import { Grid } from "@mui/material";
import { memo, useEffect, useState } from "react"; import { memo, useEffect, useState } from "react";
import DefaultTask from "../MonthCalendar/MonthCalendarBody/DefaultTask/DefaultTask"; import DefaultTask from "../DefaultTask/DefaultTask";
...@@ -36,6 +36,11 @@ const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCell ...@@ -36,6 +36,11 @@ const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCell
setIsThisCell(true); setIsThisCell(true);
handleOpen(e) handleOpen(e)
} }
if (week) {
createTaskInCellHandler(dayNumber, hours);
setIsThisCell(true);
handleOpen(e)
}
} }
return <> return <>
...@@ -48,7 +53,7 @@ const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCell ...@@ -48,7 +53,7 @@ const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCell
> >
{children} {children}
{isThisCell ? {isThisCell ?
<DefaultTask /> : null} <DefaultTask week={week}/> : null}
</Grid> </Grid>
</> </>
......
import { Box } from "@mui/material"; import { Box } from "@mui/material";
import { memo } from "react"; import { memo } from "react";
const DefaultTaskStyles = { const MonthDefaultTaskStyles = {
position: 'relative', position: 'relative',
height: '30px', height: '30px',
backgroundColor: 'lightgreen', backgroundColor: 'lightgreen',
...@@ -16,12 +16,26 @@ const DefaultTaskStyles = { ...@@ -16,12 +16,26 @@ const DefaultTaskStyles = {
paddingLeft: '5px', paddingLeft: '5px',
zIndex: '5' zIndex: '5'
} }
const WeekDefaultTaskStyles = {
boxSizing: 'border-box',
padding: '0 5px',
borderRadius: '2px',
border: '1px solid white',
backgroundColor:'lightgreen',
height: `100%`,
width: `100%`,
zIndex: 5,
textAlign: 'left',
overflow: 'hidden',
textOverflow: 'ellipsis',
}
const DefaultTask = ({ }) => { const DefaultTask = ({ week }) => {
return (<> return (<>
<Box <Box
sx={DefaultTaskStyles} sx={week ? WeekDefaultTaskStyles : MonthDefaultTaskStyles}
> >
<span> <span>
Задача Задача
......
import { Grid } from "@mui/material"; import { Grid } from "@mui/material";
import React, { memo, useEffect, useState } from "react"; import React, { memo, useEffect, useState } from "react";
import DefaultTask from "../../DefaultTask/DefaultTask"; import DefaultTask from "../../../../DefaultTask/DefaultTask";
const EmptyBox = ({ hourNumber, handleOpen, dayNumber, xs, dragTaskHandler, modal, createTaskInCellHandler, copyTask, createCopyTask }) => { const EmptyBox = ({ hourNumber, handleOpen, dayNumber, xs, dragTaskHandler, modal, createTaskInCellHandler, copyTask, createCopyTask }) => {
......
...@@ -7,7 +7,7 @@ import CalendarWeekTask from "./CalendarWeekTask/CalendarWeekTask"; ...@@ -7,7 +7,7 @@ import CalendarWeekTask from "./CalendarWeekTask/CalendarWeekTask";
function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat, handleOpen, setCurrentTask }) { function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat, handleOpen, setCurrentTask, copyTask, createCopyTask, createTaskInCellHandler, modal }) {
const [columnDayHeight, setColumnDayHeight] = useState(0) const [columnDayHeight, setColumnDayHeight] = useState(0)
const dayColumnRef = useRef('') const dayColumnRef = useRef('')
...@@ -34,7 +34,6 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat ...@@ -34,7 +34,6 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
const getBoxesInLine = (line, hoursInDay, sortedTasks, linesInDay) => { const getBoxesInLine = (line, hoursInDay, sortedTasks, linesInDay) => {
if (line) { if (line) {
let xs = 12 / hoursInDay.length
const boxes = [] const boxes = []
for (let i = 0; i < line.length; i++) { for (let i = 0; i < line.length; i++) {
if (!isNaN(line[i])) { if (!isNaN(line[i])) {
...@@ -48,13 +47,22 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat ...@@ -48,13 +47,22 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
if (taskIsThere) { if (taskIsThere) {
taskIsThere.lastHour = i taskIsThere.lastHour = i
taskIsThere.height += step taskIsThere.height += step
let tasksInHour = 0
for (let line of linesInDay) {
if (isNaN(line[i])) {
tasksInHour++
}
}
if (tasksInHour > taskIsThere.tasksInHour) {
taskIsThere.tasksInHour = tasksInHour
}
} else { } else {
let tasksInHour = 0 let tasksInHour = 0
for (let line of linesInDay) { for (let line of linesInDay) {
if (isNaN(line[i])) { if (isNaN(line[i])) {
tasksInHour++ tasksInHour++
} }
} }
boxes.push({ boxes.push({
tasksInHour: tasksInHour, tasksInHour: tasksInHour,
top: step * i, top: step * i,
...@@ -70,18 +78,18 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat ...@@ -70,18 +78,18 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
} }
} }
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) => {
const boxes = getBoxesInLine(line, hoursInDay, sortedTasks, linesInDay) const boxes = getBoxesInLine(line, hoursInDay, sortedTasks, linesInDay)
return (<> return (<>
{boxes.map((task, index) => { {boxes.map((task, index) => {
const amount = task.tasksInHour const amount = task.tasksInHour
const oneTaskPrecentWidth = 100 / amount const oneTaskPrecentWidth = 100 / amount
const left = oneTaskPrecentWidth * dayColumnRef.current.offsetWidth / 100 * i const left = oneTaskPrecentWidth * dayColumnRef.current.offsetWidth / 100 * i
const oneTaskWidth = dayColumnRef.current.offsetWidth - (oneTaskPrecentWidth * dayColumnRef.current.offsetWidth / 100) * i
const zIndex = 10 + i const zIndex = 10 + i
const oneTaskWidth = dayColumnRef.current.offsetWidth - (oneTaskPrecentWidth * dayColumnRef.current.offsetWidth / 100) * i
return ( return (
<CalendarWeekTask <CalendarWeekTask
key={index} key={index}
...@@ -91,21 +99,30 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat ...@@ -91,21 +99,30 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
task={task.task} task={task.task}
top={task.top} top={task.top}
zIndex={zIndex} zIndex={zIndex}
handleOpen={handleOpen} handleOpen={handleOpen}
setCurrentTask={setCurrentTask} setCurrentTask={setCurrentTask}
modal={modal}
> >
</CalendarWeekTask> </CalendarWeekTask>
)
)
})} })}
</>) </>)
})} })}
{hoursInDay?.map((hour, i) => { {hoursInDay?.map((hour, i) => {
return ( return (
<CalendarStandartCell key={i} week={true}> <CalendarStandartCell
key={i}
week={true}
createTaskInCellHandler={createTaskInCellHandler}
handleOpen={handleOpen}
dayNumber={day}
hours={hour}
modal={modal}
>
</CalendarStandartCell> </CalendarStandartCell>
) )
})} })}
......
...@@ -2,8 +2,8 @@ import { Box } from "@mui/material" ...@@ -2,8 +2,8 @@ import { Box } from "@mui/material"
import { useEffect, useState } from "react" import { useEffect, useState } from "react"
function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, setCurrentTask}) { function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, setCurrentTask, modal}) {
const [zIndexStyle, setZIndexStyle] = useState(10)
const [color, setColor] = useState('') const [color, setColor] = useState('')
useEffect(() => { useEffect(() => {
if (task.priority) { if (task.priority) {
...@@ -13,8 +13,15 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, ...@@ -13,8 +13,15 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen,
} else { } else {
setColor('rgb(171, 157, 157);') setColor('rgb(171, 157, 157);')
} }
setZIndexStyle(zIndex)
}, [task]) }, [task])
useEffect(() => {
if (!modal) {
setZIndexStyle(zIndex)
}
}, [modal])
const onClickTaskHandler = (e, task) => { const onClickTaskHandler = (e, task) => {
e.stopPropagation(); e.stopPropagation();
setCurrentTask((prevState) => { setCurrentTask((prevState) => {
...@@ -26,19 +33,21 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, ...@@ -26,19 +33,21 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen,
} }
} }
}); });
setZIndexStyle(100)
handleOpen(e) handleOpen(e)
} }
const styles = { const styles = {
borderRadius: '5px', boxSizing: 'border-box',
borderRadius: '3px',
border: '1px solid white', border: '1px solid white',
backgroundColor: color, backgroundColor: color,
height: `${height}px`, height: `${height - 1}px`,
width: `${width}px`, width: `${width - 1}px`,
position: 'absolute', position: 'absolute',
left: `${left}px`, left: left,
top: top, top: top,
zIndex: zIndex, zIndex: zIndexStyle,
textAlign: 'left', textAlign: 'left',
overflow: 'hidden', overflow: 'hidden',
textOverflow: 'ellipsis', textOverflow: 'ellipsis',
...@@ -46,9 +55,6 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, ...@@ -46,9 +55,6 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen,
cursor: 'pointer', cursor: 'pointer',
boxShadow: 'inset 0 0 100px 100px rgba(255, 255, 255, 0.3)' boxShadow: 'inset 0 0 100px 100px rgba(255, 255, 255, 0.3)'
}, },
"&:active": {
zIndex: 100
}
} }
return ( return (
......
...@@ -9,7 +9,7 @@ import CalendarStandartCell from "../../CalendarStandartCell/CalendarStandartCel ...@@ -9,7 +9,7 @@ import CalendarStandartCell from "../../CalendarStandartCell/CalendarStandartCel
import CalendarColumnDayWeek from "./CalendarColumnDayWeek/CalendarColumnDayWeek"; import CalendarColumnDayWeek from "./CalendarColumnDayWeek/CalendarColumnDayWeek";
import { getCurrentWeekDayString } from "./Helpers"; import { getCurrentWeekDayString } from "./Helpers";
function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, tasks, currentTask, setCurrentTask, onChangeCurrentTaskHandler, deleteTaskHandler, sendNewTaskHandler }) { function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, tasks, currentTask, setCurrentTask, onChangeCurrentTaskHandler, deleteTaskHandler, sendNewTaskHandler, createTaskInCellHandler }) {
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) => {
setModal({ setModal({
...@@ -28,7 +28,6 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t ...@@ -28,7 +28,6 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t
setCurrentTask({}) setCurrentTask({})
}; };
return ( return (
<> <>
<Box style={{ marginBottom: '30px' }}> <Box style={{ marginBottom: '30px' }}>
...@@ -78,6 +77,8 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t ...@@ -78,6 +77,8 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t
hourFormat={hourFormat} hourFormat={hourFormat}
setCurrentTask={setCurrentTask} setCurrentTask={setCurrentTask}
handleOpen={handleOpen} handleOpen={handleOpen}
createTaskInCellHandler={createTaskInCellHandler}
modal={modal.open}
/> />
) )
})} })}
......
...@@ -79,6 +79,34 @@ function WeekCalendar() { ...@@ -79,6 +79,34 @@ function WeekCalendar() {
} }
}, []); }, []);
const createTaskInCellHandler = (dayNumber, dayHour) => {
let hour
if (!isNaN(dayHour)) {
hour = dayHour
} else {
hour = parseInt(dayHour.split(':')[0])
}
let hourDue
if (hourFormat) {
hourDue = hour + 1
} else {
hourDue = hour + 2
}
const newTask = {
title: "Задача",
description: "описание",
priority: null,
dateTimeStart: dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, hour, 0)),
dateTimeDue: dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, hourDue, 59)),
infoForCell: {
startHour: hour,
endHour: hourDue,
startDay: dayNumber
}
}
setCurrentTask((newTask))
}
const sendNewTaskHandler = async () => { const sendNewTaskHandler = async () => {
const timeEndHour = currentTask.infoForCell.endHour const timeEndHour = currentTask.infoForCell.endHour
const timeStartHour = currentTask.infoForCell.startHour const timeStartHour = currentTask.infoForCell.startHour
...@@ -132,6 +160,7 @@ function WeekCalendar() { ...@@ -132,6 +160,7 @@ function WeekCalendar() {
hourFormat={hourFormat} hourFormat={hourFormat}
setHourFormat={setHourFormat} setHourFormat={setHourFormat}
hoursInDay={hoursInDay} hoursInDay={hoursInDay}
createTaskInCellHandler={createTaskInCellHandler}
/> />
</> </>
); );
......
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