Adam Shaw 7 лет назад
Родитель
Сommit
3e911bd215
2 измененных файлов с 34 добавлено и 5 удалено
  1. 22 5
      src/interactions/EventDragging.ts
  2. 12 0
      src/reducers/event-store.ts

+ 22 - 5
src/interactions/EventDragging.ts

@@ -18,6 +18,7 @@ export default class EventDragging {
   draggingSeg: Seg
   receivingCalendar: Calendar
   validMutation: EventMutation
+  mutatedRelatedEvents: EventStore
 
   constructor(component: DateComponent) {
     this.component = component
@@ -124,6 +125,7 @@ export default class EventDragging {
 
       this.receivingCalendar = receivingCalendar
       this.validMutation = validMutation
+      this.mutatedRelatedEvents = mutatedRelatedEvents
     }
   }
 
@@ -142,15 +144,30 @@ export default class EventDragging {
     this.unrenderDrag()
 
     if (this.validMutation) {
-      this.receivingCalendar.dispatch({
-        type: 'MUTATE_EVENTS',
-        mutation: this.validMutation,
-        instanceId: this.draggingSeg.eventRange.eventInstance.instanceId
-      })
+      let initialCalendar = this.hitDragging.initialHit.component.getCalendar()
+
+      if (this.receivingCalendar === initialCalendar) {
+        this.receivingCalendar.dispatch({
+          type: 'MUTATE_EVENTS',
+          mutation: this.validMutation,
+          instanceId: this.draggingSeg.eventRange.eventInstance.instanceId
+        })
+      } else {
+        initialCalendar.dispatch({
+          type: 'REMOVE_EVENTS',
+          eventStore: this.mutatedRelatedEvents
+        })
+        this.receivingCalendar.dispatch({
+          type: 'ADD_EVENTS',
+          eventStore: this.mutatedRelatedEvents,
+          stick: true // TODO: use this param
+        })
+      }
     }
 
     this.receivingCalendar = null
     this.validMutation = null
+    this.mutatedRelatedEvents = null
     this.draggingSeg = null
   }
 

+ 12 - 0
src/reducers/event-store.ts

@@ -134,11 +134,23 @@ export function reduceEventStore(eventStore: EventStore, action: any, calendar:
     case 'ADD_EVENTS':
       return mergeStores(eventStore, action.eventStore)
 
+    case 'REMOVE_EVENTS':
+      return excludeEventInstances(eventStore, action.eventStore)
+
     default:
       return eventStore
   }
 }
 
+function excludeEventInstances(eventStore: EventStore, removals: EventStore) {
+  return {
+    defs: eventStore.defs,
+    instances: filterHash(eventStore.instances, function(instance: EventInstance) {
+      return !removals.instances[instance.instanceId]
+    })
+  }
+}
+
 function excludeSource(eventStore: EventStore, sourceId: string): EventStore {
   return {
     defs: filterHash(eventStore.defs, function(def: EventDef) {