Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
planner-team-one
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
21
Issues
21
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Евгений Положенцев
planner-team-one
Commits
989e9d5d
Commit
989e9d5d
authored
Dec 17, 2022
by
Ermolaev Timur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#11
Реализовал логику модалки и нажатия
parent
cf6fe923
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
146 additions
and
39 deletions
+146
-39
CalendarColumnDayWeek.js
...lendarBody/CalendarColumnDayWeek/CalendarColumnDayWeek.js
+4
-15
CalendarWeekTask.js
...alendarColumnDayWeek/CalendarWeekTask/CalendarWeekTask.js
+16
-1
WeekCalendarBody.js
...lendars/WeekCalendar/WeekCalendarBody/WeekCalendarBody.js
+49
-10
WeekCalendar.js
planner-front/src/containers/WeekCalendar/WeekCalendar.js
+77
-13
No files found.
planner-front/src/components/Calendars/WeekCalendar/WeekCalendarBody/CalendarColumnDayWeek/CalendarColumnDayWeek.js
View file @
989e9d5d
...
@@ -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
})
{
function
CalendarColumnDayWeek
({
hoursInDay
,
tasks
,
month
,
year
,
day
,
hourFormat
,
handleOpen
,
setCurrentTask
})
{
const
[
columnDayHeight
,
setColumnDayHeight
]
=
useState
(
0
)
const
[
columnDayHeight
,
setColumnDayHeight
]
=
useState
(
0
)
const
dayColumnRef
=
useRef
(
''
)
const
dayColumnRef
=
useRef
(
''
)
...
@@ -19,19 +19,6 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
...
@@ -19,19 +19,6 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
return
getHoursInDayNumbers
(
hoursInDay
)
return
getHoursInDayNumbers
(
hoursInDay
)
},
[
hoursInDay
])
},
[
hoursInDay
])
const
taskStyle
=
{
backgroundColor
:
'red'
,
height
:
`
${
columnDayHeight
/
hours
.
length
}
px`
,
width
:
'96%'
,
margin
:
'0 auto'
,
position
:
'absolute'
,
bottom
:
0
,
marginLeft
:
'auto'
,
marginRight
:
'auto'
,
left
:
'0'
,
right
:
'0'
,
}
const
availableTasks
=
useMemo
(()
=>
{
const
availableTasks
=
useMemo
(()
=>
{
return
getAvailableTasks
(
tasks
,
year
,
month
,
day
)
return
getAvailableTasks
(
tasks
,
year
,
month
,
day
)
},
[
tasks
,
month
,
year
,
day
])
},
[
tasks
,
month
,
year
,
day
])
...
@@ -82,7 +69,7 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
...
@@ -82,7 +69,7 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
return
boxes
return
boxes
}
}
}
}
const
arr
=
[
'red'
,
'blue'
,
'yellow'
,
'purple'
,
'green'
]
return
(
<>
return
(
<>
<
Grid
item
xs
=
{
12
/
7
}
ref
=
{
dayColumnRef
}
sx
=
{{
position
:
'relative'
}}
>
<
Grid
item
xs
=
{
12
/
7
}
ref
=
{
dayColumnRef
}
sx
=
{{
position
:
'relative'
}}
>
...
@@ -104,6 +91,8 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
...
@@ -104,6 +91,8 @@ 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
}
setCurrentTask
=
{
setCurrentTask
}
>
>
<
/CalendarWeekTask
>
<
/CalendarWeekTask
>
...
...
planner-front/src/components/Calendars/WeekCalendar/WeekCalendarBody/CalendarColumnDayWeek/CalendarWeekTask/CalendarWeekTask.js
View file @
989e9d5d
...
@@ -2,7 +2,7 @@ import { Box } from "@mui/material"
...
@@ -2,7 +2,7 @@ import { Box } from "@mui/material"
import
{
useEffect
,
useState
}
from
"react"
import
{
useEffect
,
useState
}
from
"react"
function
CalendarWeekTask
({
height
,
width
,
left
,
top
,
task
,
zIndex
})
{
function
CalendarWeekTask
({
height
,
width
,
left
,
top
,
task
,
zIndex
,
handleOpen
,
setCurrentTask
})
{
const
[
color
,
setColor
]
=
useState
(
''
)
const
[
color
,
setColor
]
=
useState
(
''
)
useEffect
(()
=>
{
useEffect
(()
=>
{
...
@@ -15,6 +15,20 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex }) {
...
@@ -15,6 +15,20 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex }) {
}
}
},
[
task
])
},
[
task
])
const
onClickTaskHandler
=
(
e
,
task
)
=>
{
e
.
stopPropagation
();
setCurrentTask
((
prevState
)
=>
{
return
{
...
task
,
infoForCell
:
{
...
task
.
infoForCell
,
endHour
:
task
.
infoForCell
.
endHour
+
1
}
}
});
handleOpen
(
e
)
}
const
styles
=
{
const
styles
=
{
borderRadius
:
'5px'
,
borderRadius
:
'5px'
,
border
:
'1px solid white'
,
border
:
'1px solid white'
,
...
@@ -39,6 +53,7 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex }) {
...
@@ -39,6 +53,7 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex }) {
return
(
return
(
<
Box
<
Box
onClick
=
{(
e
)
=>
{
onClickTaskHandler
(
e
,
task
)}}
sx
=
{
styles
}
>
sx
=
{
styles
}
>
<
span
style
=
{{
textOverflow
:
'ellipsis'
,
padding
:
'5px 0 0 5px'
}}
>
<
span
style
=
{{
textOverflow
:
'ellipsis'
,
padding
:
'5px 0 0 5px'
}}
>
{
task
.
title
}
{
task
.
title
}
...
...
planner-front/src/components/Calendars/WeekCalendar/WeekCalendarBody/WeekCalendarBody.js
View file @
989e9d5d
import
{
FormControlLabel
,
Grid
,
Switch
}
from
"@mui/material"
;
import
{
FormControlLabel
,
Grid
,
Switch
}
from
"@mui/material"
;
import
{
Box
}
from
"@mui/system"
;
import
{
Box
}
from
"@mui/system"
;
import
{
useState
}
from
"react"
;
import
ModalTask
from
"../../../UI/ModalTask/ModalTask"
;
import
MonthCalendarModalContent
from
"../../CalendarModalTaskContent/CalendarModalTaskContent"
;
import
CalendarRow
from
"../../CalendarRow/CalendarRow"
;
import
CalendarRow
from
"../../CalendarRow/CalendarRow"
;
import
CalendarSmallCell
from
"../../CalendarSmallCell/CalendarSmallCell"
;
import
CalendarSmallCell
from
"../../CalendarSmallCell/CalendarSmallCell"
;
import
CalendarStandartCell
from
"../../CalendarStandartCell/CalendarStandartCell"
;
import
CalendarStandartCell
from
"../../CalendarStandartCell/CalendarStandartCell"
;
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
})
{
function
WeekCalendarBody
({
week
,
hoursInDay
,
hourFormat
,
setHourFormat
,
date
,
tasks
,
currentTask
,
setCurrentTask
,
onChangeCurrentTaskHandler
,
deleteTaskHandler
,
sendNewTaskHandler
})
{
const
[
modal
,
setModal
]
=
useState
({
open
:
false
,
y
:
0
,
x
:
0
,
});
const
handleOpen
=
(
e
)
=>
{
setModal
({
open
:
true
,
yClick
С
ordinates
:
e
.
clientY
,
xClick
С
ordinates
:
e
.
clientX
,
yDivClick
:
e
.
nativeEvent
.
offsetY
,
xDivClick
:
e
.
nativeEvent
.
offsetX
,
yDiv
:
e
.
target
.
offsetHeight
,
xDiv
:
e
.
target
.
offsetWidth
,
})
};
const
handleClose
=
()
=>
{
setModal
({
...
modal
,
open
:
false
})
setCurrentTask
({})
};
return
(
return
(
...
@@ -48,15 +68,17 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t
...
@@ -48,15 +68,17 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t
<
CalendarRow
week
=
{
true
}
>
<
CalendarRow
week
=
{
true
}
>
{
week
?.
map
((
weekDay
,
i
)
=>
{
{
week
?.
map
((
weekDay
,
i
)
=>
{
return
(
return
(
<
CalendarColumnDayWeek
<
CalendarColumnDayWeek
key
=
{
i
}
key
=
{
i
}
hoursInDay
=
{
hoursInDay
}
hoursInDay
=
{
hoursInDay
}
tasks
=
{
tasks
}
tasks
=
{
tasks
}
month
=
{
date
.
month
}
month
=
{
date
.
month
}
year
=
{
date
.
year
}
year
=
{
date
.
year
}
day
=
{
weekDay
}
day
=
{
weekDay
}
hourFormat
=
{
hourFormat
}
hourFormat
=
{
hourFormat
}
/
>
setCurrentTask
=
{
setCurrentTask
}
handleOpen
=
{
handleOpen
}
/
>
)
)
})}
})}
<
/CalendarRow
>
<
/CalendarRow
>
...
@@ -65,6 +87,23 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t
...
@@ -65,6 +87,23 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t
<
/CalendarRow
>
<
/CalendarRow
>
<
/Grid
>
<
/Grid
>
<
/Box
>
<
/Box
>
<
ModalTask
modal
=
{
modal
}
handleClose
=
{()
=>
{
handleClose
()
}}
>
<
MonthCalendarModalContent
title
=
{
currentTask
.
title
}
description
=
{
currentTask
.
description
}
priority
=
{
currentTask
.
priority
}
id
=
{
currentTask
.
id
}
startHour
=
{
currentTask
.
infoForCell
?.
startHour
}
endHour
=
{
currentTask
.
infoForCell
?.
endHour
}
onChangeCurrentTaskHandler
=
{(
e
)
=>
{
onChangeCurrentTaskHandler
(
e
)
}}
sendNewTaskHandler
=
{()
=>
{
sendNewTaskHandler
();
handleClose
()
}}
deleteTaskHandler
=
{()
=>
{
deleteTaskHandler
(
currentTask
.
id
);
handleClose
()
}}
/
>
<
/ModalTask
>
<
/
>
<
/
>
);
);
}
}
...
...
planner-front/src/containers/WeekCalendar/WeekCalendar.js
View file @
989e9d5d
...
@@ -3,23 +3,26 @@ import { useEffect, useState, useMemo, useCallback } from 'react';
...
@@ -3,23 +3,26 @@ import { useEffect, useState, useMemo, useCallback } from 'react';
import
{
useDispatch
,
useSelector
}
from
'react-redux'
;
import
{
useDispatch
,
useSelector
}
from
'react-redux'
;
import
WeekCalendarBody
from
'../../components/Calendars/WeekCalendar/WeekCalendarBody/WeekCalendarBody'
;
import
WeekCalendarBody
from
'../../components/Calendars/WeekCalendar/WeekCalendarBody/WeekCalendarBody'
;
import
WeekCalendarHeader
from
'../../components/Calendars/WeekCalendar/WeekCalendarHeader/WeekCalendarHeader'
import
WeekCalendarHeader
from
'../../components/Calendars/WeekCalendar/WeekCalendarHeader/WeekCalendarHeader'
import
{
getWeekInfoString
,
getWeekFromCurrentDate
}
from
'../../helpers/CalendarHelpers'
;
import
{
getWeekInfoString
,
getWeekFromCurrentDate
,
dateToISOLikeButLocal
}
from
'../../helpers/CalendarHelpers'
;
import
{
fetchCalendarTasks
}
from
'../../store/actions/tasksActions'
;
import
{
addCalendarTask
,
deleteCalendarTask
,
editCalendarTask
,
fetchCalendarTasks
}
from
'../../store/actions/tasksActions'
;
function
WeekCalendar
()
{
function
WeekCalendar
()
{
const
dispatch
=
useDispatch
();
const
dispatch
=
useDispatch
();
const
{
calendarTasks
}
=
useSelector
(
state
=>
state
.
tasks
);
const
{
calendarTasks
}
=
useSelector
(
state
=>
state
.
tasks
);
const
user
=
useSelector
(
state
=>
state
.
users
?.
user
);
const
user
=
useSelector
(
state
=>
state
.
users
?.
user
);
const
[
date
,
setDate
]
=
useState
({
year
:
''
,
month
:
''
,
currentDay
:
''
})
const
[
dateNow
,
setDateNow
]
=
useState
({
year
:
''
,
month
:
''
,
currentDay
:
''
})
const
[
currentTask
,
setCurrentTask
]
=
useState
({
title
:
''
,
description
:
''
,
priority
:
null
,
infoForCell
:
{
startHour
:
null
,
endHour
:
null
}
})
const
[
hourFormat
,
setHourFormat
]
=
useState
(
false
);
const
[
hourFormat
,
setHourFormat
]
=
useState
(
false
);
const
[
userId
,
setUserId
]
=
useState
(
''
)
useEffect
(()
=>
{
useEffect
(()
=>
{
const
year
=
new
Date
().
getFullYear
()
const
year
=
new
Date
().
getFullYear
()
const
month
=
new
Date
().
getMonth
()
const
month
=
new
Date
().
getMonth
()
const
currentDay
=
moment
().
date
()
const
currentDay
=
moment
().
date
()
setDate
({
year
:
year
,
month
:
month
,
currentDay
:
currentDay
})
setDateNow
({
year
:
year
,
month
:
month
,
currentDay
:
currentDay
})
// dispatch(fetchCalendarTasks())
dispatch
(
fetchCalendarTasks
(
user
.
id
))
setUserId
(
user
.
id
)
},
[])
},
[])
const
hoursInDay
=
useMemo
(()
=>
{
const
hoursInDay
=
useMemo
(()
=>
{
...
@@ -33,26 +36,82 @@ function WeekCalendar() {
...
@@ -33,26 +36,82 @@ function WeekCalendar() {
},
[
hourFormat
])
},
[
hourFormat
])
const
week
=
useMemo
(()
=>
{
const
week
=
useMemo
(()
=>
{
return
getWeekFromCurrentDate
(
date
.
year
,
date
.
month
,
date
.
currentDay
)
return
getWeekFromCurrentDate
(
dateNow
.
year
,
dateNow
.
month
,
dateNow
.
currentDay
)
},
[
date
])
},
[
dateNow
])
const
weekInfo
=
useMemo
(()
=>
{
return
getWeekInfoString
(
week
,
dateNow
)
},
[
dateNow
,
week
])
const
incrementWeek
=
useCallback
(()
=>
{
const
incrementWeek
=
useCallback
(()
=>
{
setDate
((
prevState
)
=>
{
setDate
Now
((
prevState
)
=>
{
const
newDate
=
new
Date
(
prevState
.
year
,
prevState
.
month
,
prevState
.
currentDay
+
7
)
const
newDate
=
new
Date
(
prevState
.
year
,
prevState
.
month
,
prevState
.
currentDay
+
7
)
return
{
year
:
newDate
.
getFullYear
(),
month
:
newDate
.
getMonth
(),
currentDay
:
moment
(
newDate
).
date
()
}
return
{
year
:
newDate
.
getFullYear
(),
month
:
newDate
.
getMonth
(),
currentDay
:
moment
(
newDate
).
date
()
}
})
})
},
[])
},
[])
const
decrementWeek
=
useCallback
(()
=>
{
const
decrementWeek
=
useCallback
(()
=>
{
setDate
((
prevState
)
=>
{
setDate
Now
((
prevState
)
=>
{
const
newDate
=
new
Date
(
prevState
.
year
,
prevState
.
month
,
prevState
.
currentDay
-
7
)
const
newDate
=
new
Date
(
prevState
.
year
,
prevState
.
month
,
prevState
.
currentDay
-
7
)
return
{
year
:
newDate
.
getFullYear
(),
month
:
newDate
.
getMonth
(),
currentDay
:
moment
(
newDate
).
date
()
}
return
{
year
:
newDate
.
getFullYear
(),
month
:
newDate
.
getMonth
(),
currentDay
:
moment
(
newDate
).
date
()
}
})
})
},
[])
},
[])
const
weekInfo
=
useMemo
(()
=>
{
const
onChangeCurrentTaskHandler
=
useCallback
((
e
)
=>
{
return
getWeekInfoString
(
week
,
date
)
const
{
name
,
value
}
=
e
.
target
;
},
[
date
,
week
])
if
(
name
===
'startHour'
||
name
===
'endHour'
)
{
setCurrentTask
((
prevState
)
=>
{
return
{
...
prevState
,
infoForCell
:
{
...
prevState
.
infoForCell
,
[
name
]:
value
}
}
});
}
else
{
setCurrentTask
((
prevState
)
=>
{
return
{
...
prevState
,
[
name
]:
value
}
});
}
},
[]);
const
sendNewTaskHandler
=
async
()
=>
{
const
timeEndHour
=
currentTask
.
infoForCell
.
endHour
const
timeStartHour
=
currentTask
.
infoForCell
.
startHour
const
day
=
currentTask
.
infoForCell
.
startDay
const
due
=
dateToISOLikeButLocal
(
new
Date
(
dateNow
.
year
,
dateNow
.
month
,
day
,
timeEndHour
-
1
,
59
))
const
start
=
dateToISOLikeButLocal
(
new
Date
(
dateNow
.
year
,
dateNow
.
month
,
day
,
timeStartHour
,
0
))
if
(
currentTask
.
id
)
{
const
newTask
=
{
...
currentTask
,
dateTimeStart
:
start
,
dateTimeDue
:
due
,
taskId
:
currentTask
.
mainTaskId
}
delete
newTask
.
infoForCell
await
dispatch
(
editCalendarTask
(
newTask
,
currentTask
.
id
,
userId
))
}
else
{
const
newTask
=
{
...
currentTask
,
dateTimeStart
:
start
,
dateTimeDue
:
due
,
executor
:
userId
,
author
:
user
.
id
,
dateTimeDeadLine
:
due
,
}
delete
newTask
.
infoForCell
delete
newTask
.
id
await
dispatch
(
addCalendarTask
(
newTask
,
userId
))
}
}
const
deleteTaskHandler
=
async
(
taskId
)
=>
{
dispatch
(
deleteCalendarTask
(
taskId
,
userId
))
}
return
(
return
(
<>
<>
...
@@ -62,8 +121,13 @@ function WeekCalendar() {
...
@@ -62,8 +121,13 @@ function WeekCalendar() {
weekInfo
=
{
weekInfo
}
weekInfo
=
{
weekInfo
}
/
>
/
>
<
WeekCalendarBody
<
WeekCalendarBody
deleteTaskHandler
=
{
deleteTaskHandler
}
sendNewTaskHandler
=
{
sendNewTaskHandler
}
onChangeCurrentTaskHandler
=
{
onChangeCurrentTaskHandler
}
currentTask
=
{
currentTask
}
setCurrentTask
=
{
setCurrentTask
}
tasks
=
{
calendarTasks
}
tasks
=
{
calendarTasks
}
date
=
{
date
}
date
=
{
date
Now
}
week
=
{
week
}
week
=
{
week
}
hourFormat
=
{
hourFormat
}
hourFormat
=
{
hourFormat
}
setHourFormat
=
{
setHourFormat
}
setHourFormat
=
{
setHourFormat
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment