-
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.
Merge branch 'main' of github.com:depocoder/YetAnotherCalendar into dev
- Loading branch information
Showing
14 changed files
with
303 additions
and
139 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: '' | ||
labels: '' | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Describe the bug** | ||
A clear and concise description of what the bug is. | ||
|
||
**To Reproduce** | ||
Steps to reproduce the behavior: | ||
1. Go to '...' | ||
2. Click on '....' | ||
3. Scroll down to '....' | ||
4. See error | ||
|
||
**Expected behavior** | ||
A clear and concise description of what you expected to happen. | ||
|
||
**Screenshots** | ||
If applicable, add screenshots to help explain your problem. | ||
|
||
**Desktop (please complete the following information):** | ||
- OS: [e.g. iOS] | ||
- Browser [e.g. chrome, safari] | ||
- Version [e.g. 22] | ||
|
||
**Smartphone (please complete the following information):** | ||
- Device: [e.g. iPhone6] | ||
- OS: [e.g. iOS8.1] | ||
- Browser [e.g. stock browser, safari] | ||
- Version [e.g. 22] | ||
|
||
**Additional context** | ||
Add any other context about the problem here. |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
name: Feature request | ||
about: Suggest an idea for this project | ||
title: '' | ||
labels: '' | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Is your feature request related to a problem? Please describe.** | ||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] | ||
|
||
**Describe the solution you'd like** | ||
A clear and concise description of what you want to happen. | ||
|
||
**Describe alternatives you've considered** | ||
A clear and concise description of any alternative solutions or features you've considered. | ||
|
||
**Additional context** | ||
Add any other context or screenshots about the feature request here. |
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
Oops, something went wrong.