-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # .github/workflows/deploy.yaml # frontend/src/App.jsx # frontend/src/components/Calendar/Calendar.jsx # frontend/src/components/Header/Header.js # frontend/src/pages/CalendarRoute.jsx # frontend/src/pages/LoginRoute.jsx # frontend/src/style/calendar.scss # frontend/src/style/header.scss
- Loading branch information
Showing
12 changed files
with
251 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,67 @@ | ||
import React, { useRef, useEffect, useState } from "react"; | ||
import Flatpickr from "flatpickr"; | ||
import weekSelect from "flatpickr"; | ||
import React, { useEffect, useState } from "react"; | ||
import "flatpickr/dist/flatpickr.css"; | ||
import flatpickr from "flatpickr"; | ||
import { Russian } from "flatpickr/dist/l10n/ru.js"; | ||
// import flatpickr from "flatpickr"; | ||
// import { Russian } from "flatpickr/dist/l10n/ru.js"; | ||
import "../../style/DatePicker.scss"; // Для стилей компонента | ||
|
||
const DatePicker = () => { | ||
const datePickerRef = useRef(null); | ||
// const datePickerRef = useRef(null); | ||
const [currentDate, setCurrentDate] = useState(new Date()); // Текущая дата | ||
const [weekRange, setWeekRange] = useState(""); | ||
|
||
const [dateOnCalendar, setDateOnCalendar] = useState("2024-09-19"); | ||
const [weekNumber, setWeekNumber] = useState(null); | ||
// Рассчитать начало и конец недели | ||
const calculateWeekRange = (date) => { | ||
const startOfWeek = new Date(date); | ||
const endOfWeek = new Date(date); | ||
|
||
// Получаем понедельник текущей недели | ||
startOfWeek.setDate(date.getDate() - date.getDay() + 1); // Понедельник | ||
endOfWeek.setDate(startOfWeek.getDate() + 6); // Воскресенье | ||
|
||
const formatOptions = { day: "numeric", month: "long" }; | ||
const startFormatted = startOfWeek.toLocaleDateString("ru-RU", formatOptions); | ||
const endFormatted = endOfWeek.toLocaleDateString("ru-RU", formatOptions); | ||
|
||
return `${startFormatted} – ${endFormatted}`; | ||
}; | ||
|
||
// Обновить диапазон недели при изменении даты | ||
useEffect(() => { | ||
flatpickr(datePickerRef.current, { | ||
locale: Russian, | ||
onChange: [ | ||
() => { | ||
setWeekNumber( | ||
this.selectedDates[0] ? setWeekNumber(this.selectedDates[0]) : null, | ||
); | ||
console.log(weekNumber); | ||
}, | ||
], | ||
setWeekRange(calculateWeekRange(currentDate)); | ||
}, [currentDate]); | ||
|
||
// Обработчик для переключения недель | ||
const handlePrevWeek = () => { | ||
setCurrentDate((prevDate) => { | ||
const newDate = new Date(prevDate); | ||
newDate.setDate(prevDate.getDate() - 7); // Переключение на предыдущую неделю | ||
return newDate; | ||
}); | ||
}, []); | ||
}; | ||
|
||
const handleNextWeek = () => { | ||
setCurrentDate((prevDate) => { | ||
const newDate = new Date(prevDate); | ||
newDate.setDate(prevDate.getDate() + 7); // Переключение на следующую неделю | ||
return newDate; | ||
}); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<input | ||
className="calendar" | ||
type="text" | ||
ref={datePickerRef} | ||
value={dateOnCalendar} | ||
onChange={(e) => setDateOnCalendar(e.target.value)} | ||
/> | ||
<div className="date-picker-wrapper"> | ||
<div className="week-display"> | ||
<span className="week-range">{weekRange}</span> | ||
<div className="week-navigation"> | ||
<button className="prev-week-btn" onClick={handlePrevWeek}> | ||
< | ||
</button> | ||
<button className="next-week-btn" onClick={handleNextWeek}> | ||
> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
flatpickr.l10ns.default.firstDayOfWeek = 1; | ||
|
||
export default DatePicker; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.