@@ -12,10 +12,10 @@ import adaptivePlugin from "@fullcalendar/adaptive";
12
12
import dayGridPlugin from "@fullcalendar/daygrid" ;
13
13
import multiMonthPlugin from '@fullcalendar/multimonth' ;
14
14
import timeGridPlugin from "@fullcalendar/timegrid" ;
15
- import interactionPlugin from "@fullcalendar/interaction" ;
15
+ import interactionPlugin , { EventResizeDoneArg } from "@fullcalendar/interaction" ;
16
16
import listPlugin from "@fullcalendar/list" ;
17
17
import allLocales from "@fullcalendar/core/locales-all" ;
18
- import { EventContentArg , DateSelectArg } from "@fullcalendar/core" ;
18
+ import { EventContentArg , DateSelectArg , EventDropArg } from "@fullcalendar/core" ;
19
19
import momentPlugin from "@fullcalendar/moment" ;
20
20
21
21
import ErrorBoundary from "./errorBoundary" ;
@@ -83,6 +83,7 @@ import {
83
83
resourceTimeGridHeaderToolbar ,
84
84
} from "./calendarConstants" ;
85
85
import { EventOptionControl } from "./eventOptionsControl" ;
86
+ import { EventImpl } from "@fullcalendar/core/internal" ;
86
87
87
88
function fixOldData ( oldData : any ) {
88
89
if ( ! Boolean ( oldData ) ) return ;
@@ -823,20 +824,34 @@ let CalendarBasicComp = (function () {
823
824
showModal ( event , false ) ;
824
825
} , [ editEvent , showModal ] ) ;
825
826
826
- const handleDrop = useCallback ( ( eventInfo : EventType ) => {
827
+ const updateEventsOnDragOrResize = useCallback ( ( eventInfo : EventImpl ) => {
828
+ const { extendedProps, title, ...event } = eventInfo . toJSON ( ) ;
829
+
827
830
let eventsList = [ ...props . events ] ;
828
831
const eventIdx = eventsList . findIndex (
829
- ( item : EventType ) => item . id === eventInfo . id
832
+ ( item : EventType ) => item . id === event . id
830
833
) ;
831
834
if ( eventIdx > - 1 ) {
832
- eventsList [ eventIdx ] = eventInfo ;
835
+ eventsList [ eventIdx ] = {
836
+ label : title ,
837
+ ...event ,
838
+ ...extendedProps ,
839
+ } ;
833
840
handleEventDataChange ( eventsList ) ;
834
841
}
842
+ } , [ props . events , handleEventDataChange ] ) ;
843
+
844
+ const handleDrop = useCallback ( ( eventInfo : EventDropArg ) => {
845
+ updateEventsOnDragOrResize ( eventInfo . event ) ;
835
846
836
847
if ( typeof props . onDropEvent === 'function' ) {
837
848
props . onDropEvent ( "dropEvent" ) ;
838
849
}
839
- } , [ props . onDropEvent ] ) ;
850
+ } , [ props . onDropEvent , updateEventsOnDragOrResize ] ) ;
851
+
852
+ const handleResize = useCallback ( ( eventInfo : EventResizeDoneArg ) => {
853
+ updateEventsOnDragOrResize ( eventInfo . event ) ;
854
+ } , [ props . onDropEvent , updateEventsOnDragOrResize ] ) ;
840
855
841
856
return (
842
857
< Wrapper
@@ -854,7 +869,7 @@ let CalendarBasicComp = (function () {
854
869
slotEventOverlap = { false }
855
870
events = { events }
856
871
dayHeaders = { true }
857
- dayHeaderFormat = { { weekday : 'short' , month : 'numeric' , day : 'numeric' , omitCommas : true } }
872
+ // dayHeaderFormat={{ weekday: 'short', month: 'numeric', day: 'numeric', omitCommas: true }}
858
873
expandRows = { true }
859
874
multiMonthMinWidth = { 250 }
860
875
nowIndicator = { true }
@@ -944,15 +959,8 @@ let CalendarBasicComp = (function () {
944
959
props . onEvent ( "change" ) ;
945
960
}
946
961
} }
947
- eventDrop = { ( info ) => {
948
- const { extendedProps, ...event } = info . event . toJSON ( ) ;
949
- if ( info . view ) {
950
- handleDrop ( {
951
- ...event ,
952
- ...extendedProps ,
953
- } ) ;
954
- }
955
- } }
962
+ eventDrop = { handleDrop }
963
+ eventResize = { handleResize }
956
964
/>
957
965
</ ErrorBoundary >
958
966
</ Wrapper >
0 commit comments