Commit e6b8cb54 authored by Ermolaev Timur's avatar Ermolaev Timur

#85 чуть перенес компоненты календаря, вывел информацию о недели, и смену недели

parent 64d6dcee
...@@ -3,7 +3,7 @@ import { useState } from "react"; ...@@ -3,7 +3,7 @@ import { useState } from "react";
import CalendarRow from "./CalendarRow/CalendarRow"; import CalendarRow from "./CalendarRow/CalendarRow";
import CalendarSmallCell from "./CalendarSmallCell/CalendarSmallCell"; import CalendarSmallCell from "./CalendarSmallCell/CalendarSmallCell";
import CalendarStandartCell from "./CalendarStandartCell.js/CalendarStandartCell"; import CalendarStandartCell from "./CalendarStandartCell.js/CalendarStandartCell";
import ModalTask from "../UI/ModalTask/ModalTask"; import ModalTask from "../../UI/ModalTask/ModalTask";
import MonthCalendarModalContent from "../MonthCalendarModalContent/MonthCalendarModalContent"; import MonthCalendarModalContent from "../MonthCalendarModalContent/MonthCalendarModalContent";
import CalendarRowDay from "./CalendarRowDay/CalendarRowDay"; import CalendarRowDay from "./CalendarRowDay/CalendarRowDay";
......
import { Box, Typography } from '@mui/material'; import { Box, Typography } from '@mui/material';
import { memo } from 'react'; import { memo } from 'react';
import MonthDecrementButton from './MonthDecrementButton/MonthDecrementButton'; import ArrowDecrementButton from '../../../UI/ArrowDecrementButton/ArrowDecrementButton';
import MonthIncrementButton from './MonthIncrementButton/MonthIncrementButton'; import ArrowIncrementButton from '../../../UI/ArrowIncrementButton/ArrowIncrementButton';
function MonthAndYearInfo({currentMonthString, year, incrementMonth, decrementMonth}) { function MonthAndYearInfo({currentMonthString, year, incrementMonth, decrementMonth}) {
return ( return (
...@@ -15,8 +15,8 @@ function MonthAndYearInfo({currentMonthString, year, incrementMonth, decrementMo ...@@ -15,8 +15,8 @@ function MonthAndYearInfo({currentMonthString, year, incrementMonth, decrementMo
gap: '10px' gap: '10px'
}} }}
> >
<MonthDecrementButton <ArrowDecrementButton
decrementMonth={decrementMonth} onClick={decrementMonth}
/> />
<Box sx={{ flexBasis: '150px' }}> <Box sx={{ flexBasis: '150px' }}>
<Typography <Typography
...@@ -30,8 +30,8 @@ function MonthAndYearInfo({currentMonthString, year, incrementMonth, decrementMo ...@@ -30,8 +30,8 @@ function MonthAndYearInfo({currentMonthString, year, incrementMonth, decrementMo
</Typography> </Typography>
<Typography align='center'>{year}</Typography> <Typography align='center'>{year}</Typography>
</Box> </Box>
<MonthIncrementButton <ArrowIncrementButton
incrementMonth={incrementMonth} onClick={incrementMonth}
/> />
</Box> </Box>
</> ); </> );
......
import { AppBar, Toolbar} from '@mui/material'; import { AppBar, Toolbar} from '@mui/material';
import { Box } from '@mui/system'; import { Box } from '@mui/system';
import MonthAndYearInfo from './MonthAndYearInfo/MonthAndYearInfo'; import MonthAndYearInfo from './MonthAndYearInfo/MonthAndYearInfo';
import СustomSelect from '../UI/СustomSelect/СustomSelect' import СustomSelect from '../../UI/СustomSelect/СustomSelect'
const workers = [{value: '', text: '--выберите сотрудника--'}, {value: 'Василий', text: 'Василий'}, {value: 'Никита', text: 'Никита'}] const workers = [{value: '', text: '--выберите сотрудника--'}, {value: 'Василий', text: 'Василий'}, {value: 'Никита', text: 'Никита'}]
const types = [{value: 'Месяц', text: 'Месяц'}, {value: 'Неделя', text: 'Неделя'}] const types = [{value: 'Месяц', text: 'Месяц'}, {value: 'Неделя', text: 'Неделя'}]
......
import { Button, TextField } from "@mui/material"; import { Button, TextField } from "@mui/material";
import { memo } from "react"; import { memo } from "react";
import CustomSelect from '../UI/СustomSelect/СustomSelect' import CustomSelect from '../../UI/СustomSelect/СustomSelect'
const priorities = [{value: null, text: '--Приоритет--'}, {value: 'A', text: 'A'}, {value: 'B', text: 'B'}, {value: 'C', text: 'C'}] const priorities = [{value: null, text: '--Приоритет--'}, {value: 'A', text: 'A'}, {value: 'B', text: 'B'}, {value: 'C', text: 'C'}]
......
...@@ -13,15 +13,15 @@ const arrowClass = { ...@@ -13,15 +13,15 @@ const arrowClass = {
} }
function MonthDecrementButton({decrementMonth}) { function ArrowDecrementButton({onClick}) {
return ( return (
<> <>
<ArrowBackIcon <ArrowBackIcon
sx={arrowClass} sx={arrowClass}
onClick={decrementMonth} onClick={onClick}
/> />
</> ); </> );
} }
export default memo(MonthDecrementButton); export default memo(ArrowDecrementButton);
\ No newline at end of file \ No newline at end of file
...@@ -13,15 +13,15 @@ const arrowClass = { ...@@ -13,15 +13,15 @@ const arrowClass = {
} }
function MonthIncrementButton({incrementMonth}) { function ArrowIncrementButton({onClick}) {
return ( return (
<> <>
<ArrowForwardIcon <ArrowForwardIcon
sx={arrowClass} sx={arrowClass}
onClick={incrementMonth} onClick={onClick}
/> />
</> ); </> );
} }
export default memo(MonthIncrementButton); export default memo(ArrowIncrementButton);
\ No newline at end of file \ No newline at end of file
import { AppBar, Toolbar, Typography} from '@mui/material';
import { Box } from '@mui/system';
import ArrowDecrementButton from '../UI/ArrowDecrementButton/ArrowDecrementButton';
import ArrowIncrementButton from '../UI/ArrowIncrementButton/ArrowIncrementButton';
function WeekCalendarHeader({decrementWeek, incrementWeek, weekInfo}) {
return (
<>
<Box sx={{ flexGrow: 1 }}>
<AppBar position="static">
<Toolbar>
<Box sx={{width: '40%', marginBottom: '15px'}}>
<h2>Цель недели: Наладить режим сна</h2>
<Box sx={{display: 'flex', alignItems: 'center'}}>
<ArrowDecrementButton
onClick={()=>{decrementWeek()}}
/>
<Typography
variant="h6"
sx={{
flexBasis: '250px',
display: 'flex',
justifyContent: 'center',
}}
>
{weekInfo}
</Typography>
<ArrowIncrementButton
onClick={()=>{incrementWeek()}}
/>
</Box>
</Box>
</Toolbar>
</AppBar>
</Box>
</>
);
}
export default WeekCalendarHeader;
\ No newline at end of file
import { useEffect, useCallback, useState, useMemo } from 'react'; import { useEffect, useCallback, useState, useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import MonthCalendarBody from '../../components/MonthCalendarBody/MonthCalendarBody'; import MonthCalendarBody from '../../components/MonthCalendar/MonthCalendarBody/MonthCalendarBody';
import MonthCalendarHeader from '../../components/MonthCalendarHeader/MonthCalendarHeader'; import MonthCalendarHeader from '../../components/MonthCalendar/MonthCalendarHeader/MonthCalendarHeader';
import { dateToISOLikeButLocal, getCurrentMonthString, getDaysInMonth } from '../../helpers/CalendarHelpers'; import { dateToISOLikeButLocal, getCurrentMonthString, getDaysInMonth } from '../../helpers/CalendarHelpers';
import { addCalendarTask, addCopyCalendarTask, deleteCalendarTask, editCalendarTask, fetchCalendarTasks} from '../../store/actions/tasksActions'; import { addCalendarTask, addCopyCalendarTask, deleteCalendarTask, editCalendarTask, fetchCalendarTasks} from '../../store/actions/tasksActions';
...@@ -47,8 +47,8 @@ function MonthCalendar() { ...@@ -47,8 +47,8 @@ function MonthCalendar() {
}, [dateNow]) }, [dateNow])
const currentMonthString = useMemo(() => { const currentMonthString = useMemo(() => {
return getCurrentMonthString(dateNow) return getCurrentMonthString(dateNow.month)
}, [dateNow]) }, [dateNow.month])
const onChangeWorkerHandler = useCallback((event) => { const onChangeWorkerHandler = useCallback((event) => {
setWorker(event.target.value); setWorker(event.target.value);
......
import moment from 'moment'; import moment from 'moment';
import { useEffect, useState, useMemo } from 'react'; import { useEffect, useState, useMemo, useCallback } from 'react';
import { getWeekFromCurrentDate } from '../../helpers/CalendarHelpers'; import WeekCalendarHeader from '../../components/WeekCalendarHeader/WeekCalendarHeader';
import { getWeekInfoString, getWeekFromCurrentDate } from '../../helpers/CalendarHelpers';
function WeekCalendar() { function WeekCalendar() {
...@@ -18,10 +19,32 @@ function WeekCalendar() { ...@@ -18,10 +19,32 @@ function WeekCalendar() {
return getWeekFromCurrentDate(date.year, date.month, date.currentDay) return getWeekFromCurrentDate(date.year, date.month, date.currentDay)
}, [date]) }, [date])
const incrementWeek = useCallback(() => {
setDate((prevState)=>{
const newDate = new Date(prevState.year, prevState.month, prevState.currentDay + 7)
return {year: newDate.getFullYear(), month: newDate.getMonth(), currentDay: moment(newDate).date()}
})
}, [])
const decrementWeek = useCallback(() => {
setDate((prevState)=>{
const newDate = new Date(prevState.year, prevState.month, prevState.currentDay - 7)
return {year: newDate.getFullYear(), month: newDate.getMonth(), currentDay: moment(newDate).date()}
})
}, [])
const weekInfo = useMemo(()=>{
return getWeekInfoString(week, date)
}, [date])
return ( return (
<> <>
{'dasd'} <WeekCalendarHeader
incrementWeek={incrementWeek}
decrementWeek={decrementWeek}
weekInfo={weekInfo}
/>
{week.join(' ')}
</> </>
); );
} }
......
...@@ -15,9 +15,9 @@ export const getDaysInMonth = (dateNow) => { ...@@ -15,9 +15,9 @@ export const getDaysInMonth = (dateNow) => {
} }
} }
export const getCurrentMonthString = (dateNow) => { export const getCurrentMonthString = (month) => {
if (dateNow.month <= 11 && dateNow.month >= 0) { if (month <= 11 && month >= 0) {
return ["Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь", "Декабрь"][dateNow.month]; return ["Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь", "Декабрь"][month];
} else { } else {
return null return null
} }
...@@ -55,3 +55,14 @@ export const getWeekFromCurrentDate = (year, month, curDay) => { ...@@ -55,3 +55,14 @@ export const getWeekFromCurrentDate = (year, month, curDay) => {
} }
return week return week
} }
export const getWeekInfoString = (week, date) => {
if (week[0] > week[6]) {
if (date.month === 0) {
return getCurrentMonthString(11) + ' - ' + getCurrentMonthString(date.month) + ' ' + date.year
}
return getCurrentMonthString(date.month - 1) + ' - ' + getCurrentMonthString(date.month) + ' ' + date.year
} else {
return getCurrentMonthString(date.month) + ' ' + date.year
}
}
\ No newline at end of file
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