Commit 64d6dcee authored by Ermolaev Timur's avatar Ermolaev Timur

#85 Реализовал логику получение недели

parent 39724752
......@@ -10,6 +10,7 @@ import ForgottenPassword from "./containers/ForgottenPassword/ForgottenPassword"
import Projects from "./containers/Projects/Projects";
import FullProject from "./containers/FullProject/FullProject";
import NewProject from "./containers/NewProject/NewProject";
import WeekCalendar from "./containers/WeekCalendar/WeekCalendar";
const ProtectedRoute = ({isAllowed, roles, redirectUrl, children}) => {
const user = useSelector(state => state.users?.user);
......@@ -56,7 +57,7 @@ const App = () => {
isAllowed={user}
redirectUrl={"/sign-in"}
>
<h1>week page</h1>
<WeekCalendar/>
</ProtectedRoute>
}/>
......@@ -65,7 +66,7 @@ const App = () => {
isAllowed={user}
redirectUrl={"/sign-in"}
>
<h1>week page</h1>
<WeekCalendar/>
</ProtectedRoute>
}/>
......@@ -74,7 +75,7 @@ const App = () => {
isAllowed={user}
redirectUrl={"/sign-in"}
>
<MonthCalendar>month page</MonthCalendar>
<MonthCalendar></MonthCalendar>
</ProtectedRoute>
}/>
......
......@@ -8,7 +8,7 @@ const CalendarStandartCell = ({children, xs, hours, dayNumber, createTaskInCell
const [isThisCell, setIsThisCell] = useState(false)
const cellClass = {
position: 'relative',
height: linesInDay?.length ? `${40*linesInDay.length+35}px` : `${35}px`,
height: linesInDay?.length ? `${40*linesInDay.length+35}px` : `${40}px`,
borderRight: '1px solid black',
}
useEffect(()=>{
......
import moment from 'moment';
import { useEffect, useState, useMemo } from 'react';
import { getWeekFromCurrentDate } from '../../helpers/CalendarHelpers';
function WeekCalendar() {
const [date, setDate] = useState({year: '', month: '', currentDay: ''})
useEffect(()=>{
const year = new Date().getFullYear()
const month = new Date().getMonth()
const currentDay = moment().date()
setDate({year: year, month: month, currentDay: currentDay})
}, [])
const week = useMemo(()=>{
return getWeekFromCurrentDate(date.year, date.month, date.currentDay)
}, [date])
return (
<>
{'dasd'}
</>
);
}
export default WeekCalendar;
\ No newline at end of file
import moment from "moment"
export const getDaysInMonth = (dateNow) => {
if (dateNow.month <= 11 && dateNow.month >= 0) {
const newDaysInMonth = []
......@@ -31,4 +33,25 @@ export const dateToISOLikeButLocal = (date) => {
} else {
return null
}
}
export const getWeekFromCurrentDate = (year, month, curDay) => {
const week = [0, 0, 0, 0, 0, 0, 0]
const currentDayWeek = moment(new Date(year, month, curDay)).isoWeekday()
for (let i = 1; i <= 7; i++) {
if (currentDayWeek > i ) {
const day = moment(new Date(year, month, curDay - i)).date()
const dayWeek = moment(new Date(year, month, curDay - i)).isoWeekday()
week[dayWeek - 1] = day
} else if (currentDayWeek === i) {
const day = moment(new Date(year, month, curDay)).date()
const dayWeek = moment(new Date(year, month, curDay)).isoWeekday()
week[dayWeek - 1] = day
} else {
const day = moment(new Date(year, month, curDay + i - moment(new Date(year, month, curDay)).isoWeekday())).date()
const dayWeek = i - moment(new Date(year, month, curDay)).isoWeekday() + moment(new Date(year, month, curDay)).isoWeekday()
week[dayWeek - 1] = day
}
}
return week
}
\ 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