@@ -28,6 +28,24 @@ export function useCalendarEvents(props: CalendarContainerProps): CalendarEventH
28
28
[ onEditEvent ]
29
29
) ;
30
30
31
+ const invokeCreate = useCallback (
32
+ ( slotInfo : { start : Date ; end : Date ; action : string } ) => {
33
+ const action = onCreateEvent ;
34
+
35
+ if ( action ?. canExecute && editable ?. value === true ) {
36
+ // An event is considered "all day" when the duration is an exact multiple of 24 hours.
37
+ const isAllDay =
38
+ ( ( slotInfo . end . getTime ( ) - slotInfo . start . getTime ( ) ) / ( 24 * 60 * 60 * 1000 ) ) % 1 === 0 ;
39
+ action . execute ( {
40
+ startDate : slotInfo . start ,
41
+ endDate : slotInfo . end ,
42
+ allDay : isAllDay
43
+ } ) ;
44
+ }
45
+ } ,
46
+ [ onCreateEvent , editable ]
47
+ ) ;
48
+
31
49
// https://github.com/jquense/react-big-calendar/blob/master/stories/props/onSelectEvent.stories.js
32
50
const handleSelectEvent = useCallback (
33
51
( event : CalendarEvent ) => {
@@ -55,13 +73,17 @@ export function useCalendarEvents(props: CalendarContainerProps): CalendarEventH
55
73
56
74
clickRef . current = setTimeout ( ( ) => {
57
75
invokeEdit ( event ) ;
76
+ setSelected ( event ) ;
58
77
} , 250 ) ;
59
78
} ,
60
79
[ invokeEdit ]
61
80
) ;
62
81
63
82
const handleKeyPressEvent = useCallback (
64
83
( event : CalendarEvent , e : any ) => {
84
+ if ( clickRef ?. current ) {
85
+ clearTimeout ( clickRef . current ) ;
86
+ }
65
87
if ( e . key === "Enter" && selected ?. item . id === event . item . id ) {
66
88
invokeEdit ( event ) ;
67
89
}
@@ -71,20 +93,12 @@ export function useCalendarEvents(props: CalendarContainerProps): CalendarEventH
71
93
72
94
const handleCreateEvent = useCallback (
73
95
( slotInfo : { start : Date ; end : Date ; action : string } ) => {
74
- const action = onCreateEvent ;
75
-
76
- if ( action ?. canExecute && editable ?. value === true ) {
77
- // is all day : if the difference between start and end is a multiple of 24 hours
78
- const isAllday =
79
- ( ( slotInfo . end . getTime ( ) - slotInfo . start . getTime ( ) ) / ( 24 * 60 * 60 * 1000 ) ) % 1 === 0 ;
80
- action ?. execute ( {
81
- startDate : slotInfo . start ,
82
- endDate : slotInfo . end ,
83
- allDay : isAllday
84
- } ) ;
96
+ setSelected ( null ) ;
97
+ if ( ! selected ) {
98
+ invokeCreate ( slotInfo ) ;
85
99
}
86
100
} ,
87
- [ onCreateEvent , editable ]
101
+ [ invokeCreate , selected ]
88
102
) ;
89
103
90
104
const handleEventDropOrResize = useCallback (
0 commit comments