Parcourir la source

flesh out app state more

Adam Shaw il y a 7 ans
Parent
commit
9d1486c268
4 fichiers modifiés avec 42 ajouts et 19 suppressions
  1. 2 2
      src/Calendar.ts
  2. 0 1
      src/component/DateComponent.ts
  3. 8 6
      src/reducers/event-sources.ts
  4. 32 10
      src/reducers/main.ts

+ 2 - 2
src/Calendar.ts

@@ -526,8 +526,8 @@ export default class Calendar {
         this.currentDate = newDateProfile.date // might have been constrained by view dates
         this.currentDate = newDateProfile.date // might have been constrained by view dates
         this.updateToolbarButtons(newDateProfile)
         this.updateToolbarButtons(newDateProfile)
         this.dispatch({
         this.dispatch({
-          type: 'SET_ACTIVE_RANGE',
-          range: newDateProfile.activeUnzonedRange
+          type: 'SET_DATE_PROFILE',
+          dateProfile: newDateProfile
         })
         })
       }
       }
 
 

+ 0 - 1
src/component/DateComponent.ts

@@ -438,7 +438,6 @@ export default abstract class DateComponent extends Component {
 
 
 
 
   // Renders a visual indication of the selection
   // Renders a visual indication of the selection
-  // TODO: rename to `renderSelection` after legacy is gone
   renderSelection(selection: Selection) {
   renderSelection(selection: Selection) {
     this.renderHighlightSegs(this.selectionToSegs(selection))
     this.renderHighlightSegs(this.selectionToSegs(selection))
 
 

+ 8 - 6
src/reducers/event-sources.ts

@@ -101,11 +101,11 @@ export function reduceEventSourceHash(sourceHash: EventSourceHash, action: any,
       eventSource = parseSource(action.rawSource)
       eventSource = parseSource(action.rawSource)
 
 
       if (eventSource) {
       if (eventSource) {
-        if (calendar.state.activeRange) {
+        if (calendar.state.dateProfile) {
           calendar.dispatch({
           calendar.dispatch({
             type: 'FETCH_EVENT_SOURCE',
             type: 'FETCH_EVENT_SOURCE',
             sourceId: eventSource.sourceId,
             sourceId: eventSource.sourceId,
-            range: calendar.state.activeRange
+            range: calendar.state.dateProfile.activeUnzonedRange
           })
           })
         }
         }
         return assignTo({}, sourceHash, {
         return assignTo({}, sourceHash, {
@@ -188,20 +188,22 @@ export function reduceEventSourceHash(sourceHash: EventSourceHash, action: any,
         return sourceHash
         return sourceHash
       }
       }
 
 
-    case 'SET_ACTIVE_RANGE':
+    case 'SET_DATE_PROFILE':
+      let activeRange = action.dateProfile.activeUnzonedRange
+
       for (let sourceId in sourceHash) {
       for (let sourceId in sourceHash) {
         eventSource = sourceHash[sourceId]
         eventSource = sourceHash[sourceId]
 
 
         if (
         if (
           !calendar.opt('lazyFetching') ||
           !calendar.opt('lazyFetching') ||
           !eventSource.fetchRange ||
           !eventSource.fetchRange ||
-          eventSource.fetchRange.start < action.range.start ||
-          eventSource.fetchRange.end > action.range.end
+          eventSource.fetchRange.start < activeRange.start ||
+          eventSource.fetchRange.end > activeRange.end
         ) {
         ) {
           calendar.dispatch({
           calendar.dispatch({
             type: 'FETCH_EVENT_SOURCE',
             type: 'FETCH_EVENT_SOURCE',
             sourceId: eventSource.sourceId,
             sourceId: eventSource.sourceId,
-            range: action.range
+            range: activeRange
           })
           })
         }
         }
       }
       }

+ 32 - 10
src/reducers/main.ts

@@ -1,40 +1,62 @@
-import UnzonedRange from '../models/UnzonedRange'
 import Calendar from '../Calendar'
 import Calendar from '../Calendar'
+import { DateProfile } from '../DateProfileGenerator'
 import { EventSourceHash, reduceEventSourceHash } from './event-sources'
 import { EventSourceHash, reduceEventSourceHash } from './event-sources'
 import { EventStore, reduceEventStore } from './event-store'
 import { EventStore, reduceEventStore } from './event-store'
+import { Selection } from './selection'
+import { BusinessHourDef } from './business-hours'
 
 
 export interface CalendarState {
 export interface CalendarState {
   loadingLevel: number
   loadingLevel: number
-  activeRange: UnzonedRange
+  dateProfile: DateProfile
   eventSources: EventSourceHash
   eventSources: EventSourceHash
   eventStore: EventStore
   eventStore: EventStore
+  selection: Selection | null,
+  dragState: {
+    eventStore: EventStore
+    origSeg: any
+    isTouch: boolean
+  } | null
+  eventResizeState: {
+    eventStore: EventStore
+    origSeg: any
+    isTouch: boolean
+  } | null
+  businessHoursDef: BusinessHourDef
 }
 }
 
 
 export const INITIAL_STATE: CalendarState = {
 export const INITIAL_STATE: CalendarState = {
   loadingLevel: 0,
   loadingLevel: 0,
-  activeRange: null,
+  dateProfile: null,
   eventSources: {},
   eventSources: {},
   eventStore: {
   eventStore: {
     defs: {},
     defs: {},
     instances: {}
     instances: {}
-  }
+  },
+  selection: null,
+  dragState: null,
+  eventResizeState: null,
+  businessHoursDef: false
 }
 }
 
 
 export function reduce(state: CalendarState, action: any, calendar: Calendar): CalendarState {
 export function reduce(state: CalendarState, action: any, calendar: Calendar): CalendarState {
   return {
   return {
     loadingLevel: reduceLoadingLevel(state.loadingLevel, action),
     loadingLevel: reduceLoadingLevel(state.loadingLevel, action),
-    activeRange: reduceActiveRange(state.activeRange, action),
+    dateProfile: reduceDateProfile(state.dateProfile, action),
     eventSources: reduceEventSourceHash(state.eventSources, action, calendar),
     eventSources: reduceEventSourceHash(state.eventSources, action, calendar),
-    eventStore: reduceEventStore(state.eventStore, action, calendar)
+    eventStore: reduceEventStore(state.eventStore, action, calendar),
+    selection: state.selection,
+    dragState: state.dragState,
+    eventResizeState: state.eventResizeState,
+    businessHoursDef: state.businessHoursDef
   }
   }
 }
 }
 
 
-function reduceActiveRange(currentActiveRange, action: any) {
+function reduceDateProfile(currentDateProfile, action: any) {
   switch (action.type) {
   switch (action.type) {
-    case 'SET_ACTIVE_RANGE':
-      return action.range
+    case 'SET_DATE_PROFILE':
+      return action.dateProfile
     default:
     default:
-      return currentActiveRange
+      return currentDateProfile
   }
   }
 }
 }