-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalendar.js
90 lines (84 loc) · 3.17 KB
/
calendar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import {
setCurrentDate,
setSelectedDate,
setView,
setOpenCalendar,
} from "../redux/calendarSlice";
/**
* Handles month change event and updates the current date.
*
* @param {number} direction - The direction to change the month (-1 for previous month, 1 for next month).
* @param {string} currentDate - The current date object.
* @param {Function} dispatch - Redux dispatch function.
*/
export const handleMonthChange = (direction, currentDate, dispatch) => {
const newDate = new Date(currentDate);
newDate.setMonth(newDate.getMonth() + direction);
dispatch(setCurrentDate(newDate.toISOString()));
};
/**
* Handles year change event and updates the current date.
*
* @param {number} direction - The direction to change the year (-1 for previous year, 1 for next year).
* @param {string} currentDate - The current date object.
* @param {Function} dispatch - Redux dispatch function.
*/
export const handleYearChange = (direction, currentDate, dispatch) => {
const newDate = new Date(currentDate);
newDate.setFullYear(newDate.getFullYear() + direction);
dispatch(setCurrentDate(newDate.toISOString()));
};
/**
* Handles year change event and updates the current date.
*
* @param {number} direction - The direction to change the year (-1 for previous year, 1 for next year).
* @param {string} currentDate - The current date object.
* @param {Function} dispatch - Redux dispatch function.
*/
export const handleYearsChange = (direction, currentDate, dispatch) => {
const newDate = new Date(currentDate);
newDate.setFullYear(newDate.getFullYear() + direction);
dispatch(setCurrentDate(newDate.toISOString()));
};
/**
* Handles date click event and updates the selected date and view.
*
* @param {number} day - The day of the month to select.
* @param {string} currentDate - The current date object.
* @param {Function} dispatch - Redux dispatch function.
*/
export const handleDateClick = (day, currentDate, dispatch) => {
if (day) {
const current = new Date(currentDate);
const newDate = new Date(current.getFullYear(), current.getMonth(), day);
dispatch(setSelectedDate(newDate.toISOString()));
dispatch(setView("date"));
dispatch(setOpenCalendar(false));
}
};
/**
* Handles month click event and updates the current date and view.
*
* @param {number} month - The month to set (0 for January, 11 for December).
* @param {string} currentDate - The current date object.
* @param {Function} dispatch - Redux dispatch function.
*/
export const handleMonthClick = (month, currentDate, dispatch) => {
const current = new Date(currentDate);
const newDate = new Date(current.getFullYear(), month);
dispatch(setCurrentDate(newDate.toISOString()));
dispatch(setView("date"));
};
/**
* Handles year click event and updates the current date and view.
*
* @param {number} year - The year to set.
* @param {string} currentDate - The current date object.
* @param {Function} dispatch - Redux dispatch function.
*/
export const handleYearClick = (year, currentDate, dispatch) => {
const current = new Date(currentDate);
const newDate = new Date(year, current.getMonth());
dispatch(setCurrentDate(newDate.toISOString()));
dispatch(setView("month"));
};