Răsfoiți Sursa

fixes for agenda view touch event dragging

Adam Shaw 7 ani în urmă
părinte
comite
0bf1627262
2 a modificat fișierele cu 20 adăugiri și 10 ștergeri
  1. 3 2
      src/common/GlobalContext.ts
  2. 17 8
      src/interactions/EventDragging.ts

+ 3 - 2
src/common/GlobalContext.ts

@@ -8,6 +8,7 @@ import EventDragging from '../interactions/EventDragging'
 import Calendar from '../Calendar'
 
 // TODO: how to accept external drags?
+// TODO: rename to BrowserContext?
 
 export class GlobalContext { // TODO: rename file to something better
 
@@ -15,8 +16,8 @@ export class GlobalContext { // TODO: rename file to something better
   componentCnt: number = 0
   componentHash = {}
   listenerHash = {}
-  selectedCalendar: Calendar // *date* selection
-  eventSelectedCalendar: Calendar
+  selectedCalendar: Calendar // *date* selection // TODO: move to component just like eventSelected?
+  eventSelectedComponent: DateComponent
 
   registerComponent(component: DateComponent) {
     this.componentHash[component.uid] = component

+ 17 - 8
src/interactions/EventDragging.ts

@@ -58,24 +58,29 @@ export default class EventDragging {
     let { globalContext } = this
     let calendar = this.component.getCalendar()
 
-    if (globalContext.eventSelectedCalendar && globalContext.eventSelectedCalendar !== calendar) {
-      globalContext.eventSelectedCalendar.dispatch({
-        type: 'CLEAR_SELECTED_EVENT'
-      })
-      globalContext.eventSelectedCalendar = null
+    // TODO: nicer accessors in GlobalContext for this?
+    if (globalContext.eventSelectedComponent) {
+      let selectedCalendar = globalContext.eventSelectedComponent.getCalendar()
+
+      if (selectedCalendar !== calendar) {
+        selectedCalendar.dispatch({
+          type: 'CLEAR_SELECTED_EVENT'
+        })
+        globalContext.eventSelectedComponent = null
+      }
     }
 
     this.draggingSeg = (ev.el as any).fcSeg
 
     if (ev.isTouch) {
-      globalContext.eventSelectedCalendar = calendar
-
       let eventInstanceId = this.draggingSeg.eventRange.eventInstance.instanceId
 
       calendar.dispatch({
         type: 'SELECT_EVENT',
         eventInstanceId
       })
+
+      this.globalContext.eventSelectedComponent = this.component
     }
   }
 
@@ -138,7 +143,11 @@ export default class EventDragging {
   }
 
   onDocumentPointerUp = (ev, isTouchScroll) => {
-    if (!this.mutation && !isTouchScroll) {
+    if (
+      !this.mutation &&
+      !isTouchScroll &&
+      this.globalContext.eventSelectedComponent === this.component
+    ) {
       this.component.getCalendar().dispatch({
         type: 'CLEAR_SELECTED_EVENT'
       })