Commit e82f60d5 authored by Ermolaev Timur's avatar Ermolaev Timur

#85 отобразил календарь-часы для дней недели

parent 92f23697
import { Grid } from "@mui/material"; import { Grid } from "@mui/material";
const CalendarRow = ({children}) => { const CalendarRow = ({children, week}) => {
return <> return <>
<Grid <Grid
container container
align='center' align='center'
sx={{borderBottom: '1px solid black', borderRight: '1px solid black', borderLeft: '1px solid black'}} sx={{borderBottom: week ? null : '1px solid black', borderRight: '1px solid black', borderLeft: '1px solid black'}}
> >
{children} {children}
</Grid> </Grid>
......
import { Grid } from "@mui/material"; import { Grid } from "@mui/material";
import { memo } from "react"; import { memo } from "react";
const CalendarSmallCell = ({children, xs}) => { const CalendarSmallCell = ({children, xs, week}) => {
return <> return <>
<Grid align='center' item xs={xs} sx={{borderRight: '1px solid black'}}> <Grid align='center' item xs={xs} sx={{borderRight: week ? null : '1px solid black', height: week ? '40px' : null, borderBottom: week ? '1px solid black' : null,}}>
{children} {children}
</Grid> </Grid>
</> </>
......
...@@ -4,13 +4,16 @@ import DefaultTask from "../DefaultTask/DefaultTask"; ...@@ -4,13 +4,16 @@ import DefaultTask from "../DefaultTask/DefaultTask";
const CalendarStandartCell = ({children, xs, hours, dayNumber, createTaskInCellHandler, handleOpen, modal, dragTaskHandler, linesInDay}) => { const CalendarStandartCell = ({children, xs, hours, dayNumber, createTaskInCellHandler, handleOpen, modal, dragTaskHandler, linesInDay, week}) => {
const [isThisCell, setIsThisCell] = useState(false) const [isThisCell, setIsThisCell] = useState(false)
const cellClass = { const cellClass = {
position: 'relative', position: 'relative',
height: linesInDay?.length ? `${40*linesInDay.length+35}px` : `${40}px`, height: linesInDay?.length ? `${40*linesInDay.length+35}px` : `${40}px`,
borderRight: '1px solid black', borderRight: '1px solid black',
borderBottom: week ?'1px solid black' : null,
} }
useEffect(()=>{ useEffect(()=>{
if(!modal) { if(!modal) {
setIsThisCell(false); setIsThisCell(false);
...@@ -27,7 +30,7 @@ const CalendarStandartCell = ({children, xs, hours, dayNumber, createTaskInCell ...@@ -27,7 +30,7 @@ const CalendarStandartCell = ({children, xs, hours, dayNumber, createTaskInCell
dragTaskHandler(dayNumber, parseInt(hours.split(':')[0])) dragTaskHandler(dayNumber, parseInt(hours.split(':')[0]))
} }
const onClickHandler = (e) => { const onClickHandler = (e) => {
if (!linesInDay?.length) { if (linesInDay?.length) {
createTaskInCellHandler(dayNumber, hours); createTaskInCellHandler(dayNumber, hours);
setIsThisCell(true); setIsThisCell(true);
handleOpen(e) handleOpen(e)
......
import { FormControlLabel, Switch } from "@mui/material"; import { FormControlLabel, Grid, Switch } from "@mui/material";
import { Box } from "@mui/system"; import { Box } from "@mui/system";
import CalendarRow from "../../MonthCalendar/MonthCalendarBody/CalendarRow/CalendarRow"; import CalendarRow from "../../MonthCalendar/MonthCalendarBody/CalendarRow/CalendarRow";
import CalendarSmallCell from "../../MonthCalendar/MonthCalendarBody/CalendarSmallCell/CalendarSmallCell"; import CalendarSmallCell from "../../MonthCalendar/MonthCalendarBody/CalendarSmallCell/CalendarSmallCell";
import CalendarStandartCell from "../../MonthCalendar/MonthCalendarBody/CalendarStandartCell.js/CalendarStandartCell"; import CalendarStandartCell from "../../MonthCalendar/MonthCalendarBody/CalendarStandartCell.js/CalendarStandartCell";
import { getCurrentWeekDayString } from "./Helpers"; import { getCurrentWeekDayString } from "./Helpers";
function WeekCalendarBody({week, date, hourFormat, setHourFormat}) { function WeekCalendarBody({week, hoursInDay, hourFormat, setHourFormat}) {
return ( return (
<> <>
...@@ -31,7 +31,34 @@ function WeekCalendarBody({week, date, hourFormat, setHourFormat}) { ...@@ -31,7 +31,34 @@ function WeekCalendarBody({week, date, hourFormat, setHourFormat}) {
</CalendarRow> </CalendarRow>
</Box> </Box>
<Grid container>
<CalendarRow week={true}>
<Grid item xs={0.995} flexDirection='column'>
{hoursInDay?.map((hour, i)=>{
return (
<CalendarSmallCell key={i} week={true}>
{hour}
</CalendarSmallCell>)
})}
</Grid>
<Grid item xs={11.005}>
<CalendarRow week={true}>
{week?.map((weekDay, i)=>{
return (
<Grid item key={i} xs={12/week.length}>
{hoursInDay?.map((hour, i)=>{
return (
<CalendarStandartCell key={i} week={true}>
</CalendarStandartCell>)
})}
</Grid>)
})}
</CalendarRow>
</Grid>
</CalendarRow>
</Grid>
</Box> </Box>
</> </>
); );
......
...@@ -17,6 +17,16 @@ function WeekCalendar() { ...@@ -17,6 +17,16 @@ function WeekCalendar() {
setDate({year: year, month: month, currentDay: currentDay}) setDate({year: year, month: month, currentDay: currentDay})
}, []) }, [])
const hoursInDay = useMemo(()=>{
let arr
if (hourFormat) {
arr = ['8:00', '9:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00','21:00','22:00']
} else {
arr = ['8:00', '10:00', '12:00', '14:00', '16:00', '18:00', '20:00', '22:00']
}
return arr
}, [hourFormat])
const week = useMemo(()=>{ const week = useMemo(()=>{
return getWeekFromCurrentDate(date.year, date.month, date.currentDay) return getWeekFromCurrentDate(date.year, date.month, date.currentDay)
}, [date]) }, [date])
...@@ -37,7 +47,7 @@ function WeekCalendar() { ...@@ -37,7 +47,7 @@ function WeekCalendar() {
const weekInfo = useMemo(()=>{ const weekInfo = useMemo(()=>{
return getWeekInfoString(week, date) return getWeekInfoString(week, date)
}, [date]) }, [date, week])
return ( return (
<> <>
...@@ -48,11 +58,10 @@ function WeekCalendar() { ...@@ -48,11 +58,10 @@ function WeekCalendar() {
/> />
<WeekCalendarBody <WeekCalendarBody
week={week} week={week}
date={date}
hourFormat={hourFormat} hourFormat={hourFormat}
setHourFormat={setHourFormat} setHourFormat={setHourFormat}
hoursInDay={hoursInDay}
/> />
{week.join(' ')}
</> </>
); );
} }
......
...@@ -58,10 +58,10 @@ export const getWeekFromCurrentDate = (year, month, curDay) => { ...@@ -58,10 +58,10 @@ export const getWeekFromCurrentDate = (year, month, curDay) => {
export const getWeekInfoString = (week, date) => { export const getWeekInfoString = (week, date) => {
if (week[0] > week[6]) { if (week[0] > week[6]) {
if (date.month === 0) { if (date.month === 11) {
return getCurrentMonthString(11) + ' - ' + getCurrentMonthString(date.month) + ' ' + date.year return getCurrentMonthString(date.month) + ' - ' + getCurrentMonthString(0) + ' ' + date.year
} }
return getCurrentMonthString(date.month - 1) + ' - ' + getCurrentMonthString(date.month) + ' ' + date.year return getCurrentMonthString(date.month) + ' - ' + getCurrentMonthString(date.month + 1) + ' ' + date.year
} else { } else {
return getCurrentMonthString(date.month) + ' ' + date.year return getCurrentMonthString(date.month) + ' ' + date.year
} }
......
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