|
|
@@ -1,9 +1,11 @@
|
|
|
import Calendar from '../Calendar'
|
|
|
import { DateComponentRenderState } from '../component/DateComponent'
|
|
|
import { EventSourceHash } from '../structs/event-source'
|
|
|
-import { assignTo } from '../util/object'
|
|
|
import { reduceEventSourceHash } from './event-sources'
|
|
|
import { reduceEventStore } from './event-store'
|
|
|
+import { DateProfile } from '../DateProfileGenerator'
|
|
|
+import { DateSpan } from '../structs/date-span'
|
|
|
+import { EventInteractionState } from '../interactions/event-interaction-state'
|
|
|
|
|
|
export interface CalendarState extends DateComponentRenderState {
|
|
|
loadingLevel: number
|
|
|
@@ -11,76 +13,72 @@ export interface CalendarState extends DateComponentRenderState {
|
|
|
}
|
|
|
|
|
|
export function reduce(state: CalendarState, action: any, calendar: Calendar): CalendarState {
|
|
|
- let newState = {
|
|
|
- loadingLevel: reduceLoadingLevel(state.loadingLevel, action),
|
|
|
+ calendar.trigger(action.type, action) // for testing hooks
|
|
|
+
|
|
|
+ return {
|
|
|
+ dateProfile: reduceDateProfile(state.dateProfile, action),
|
|
|
eventSources: reduceEventSourceHash(state.eventSources, action, calendar),
|
|
|
eventStore: reduceEventStore(state.eventStore, action, calendar),
|
|
|
- dateProfile: state.dateProfile,
|
|
|
- selection: state.selection,
|
|
|
- dragState: state.dragState,
|
|
|
- eventResizeState: state.eventResizeState,
|
|
|
- businessHoursDef: state.businessHoursDef,
|
|
|
- selectedEventInstanceId: state.selectedEventInstanceId
|
|
|
+ businessHoursDef: state.businessHoursDef, // TODO: rename?
|
|
|
+ selection: reduceDateSelection(state.selection, action), // TODO: rename
|
|
|
+ selectedEventInstanceId: reduceSelectedEvent(state.selectedEventInstanceId, action),
|
|
|
+ dragState: reduceDrag(state.dragState, action),
|
|
|
+ eventResizeState: reduceEventResize(state.eventResizeState, action),
|
|
|
+ loadingLevel: reduceLoadingLevel(state.loadingLevel, action)
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- calendar.trigger(action.type, action) // for testing hooks
|
|
|
-
|
|
|
- switch(action.type) {
|
|
|
-
|
|
|
+function reduceDateProfile(currentDateProfile: DateProfile, action: any) {
|
|
|
+ switch (action.type) {
|
|
|
case 'SET_DATE_PROFILE':
|
|
|
- if (action.dateProfile.isValid) {
|
|
|
- newState.dateProfile = action.dateProfile
|
|
|
- calendar.view.updateMiscDateProps(action.dateProfile)
|
|
|
- }
|
|
|
- break
|
|
|
+ return action.dateProfile
|
|
|
+ default:
|
|
|
+ return currentDateProfile
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- case 'SELECT':
|
|
|
- return assignTo({}, state, {
|
|
|
- selection: action.selection
|
|
|
- })
|
|
|
+function reduceDateSelection(currentSelection: DateSpan, action: any) {
|
|
|
+ switch (action.type) {
|
|
|
+ case 'SELECT': // TODO: rename
|
|
|
+ return action.selection
|
|
|
+ case 'UNSELECT': // TODO: rename
|
|
|
+ return null
|
|
|
+ default:
|
|
|
+ return currentSelection
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- case 'UNSELECT':
|
|
|
- if (state.selection) { // if already no selection, don't bother
|
|
|
- return assignTo({}, state, {
|
|
|
- selection: null
|
|
|
- })
|
|
|
- } else {
|
|
|
- break
|
|
|
- }
|
|
|
+function reduceSelectedEvent(currentInstanceId: string, action: any): string {
|
|
|
+ switch (action.type) {
|
|
|
+ case 'SELECT_EVENT':
|
|
|
+ return action.eventInstanceId
|
|
|
+ case 'CLEAR_SELECTED_EVENT':
|
|
|
+ return ''
|
|
|
+ default:
|
|
|
+ return currentInstanceId
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+function reduceDrag(currentDrag: EventInteractionState, action: any) {
|
|
|
+ switch (action.type) {
|
|
|
case 'SET_DRAG':
|
|
|
- return assignTo({}, state, {
|
|
|
- dragState: action.dragState
|
|
|
- })
|
|
|
-
|
|
|
+ return action.dragState
|
|
|
case 'CLEAR_DRAG':
|
|
|
- return assignTo({}, state, {
|
|
|
- dragState: null
|
|
|
- })
|
|
|
-
|
|
|
- case 'SELECT_EVENT':
|
|
|
- return assignTo({}, state, {
|
|
|
- selectedEventInstanceId: action.eventInstanceId
|
|
|
- })
|
|
|
-
|
|
|
- case 'CLEAR_SELECTED_EVENT':
|
|
|
- return assignTo({}, state, {
|
|
|
- selectedEventInstanceId: null
|
|
|
- })
|
|
|
+ return null
|
|
|
+ default:
|
|
|
+ return currentDrag
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+function reduceEventResize(currentEventResize: EventInteractionState, action: any) {
|
|
|
+ switch (action.type) {
|
|
|
case 'SET_EVENT_RESIZE':
|
|
|
- return assignTo({}, state, {
|
|
|
- eventResizeState: action.eventResizeState
|
|
|
- })
|
|
|
-
|
|
|
+ return action.eventResizeState
|
|
|
case 'CLEAR_EVENT_RESIZE':
|
|
|
- return assignTo({}, state, {
|
|
|
- eventResizeState: null
|
|
|
- })
|
|
|
-
|
|
|
+ return null
|
|
|
+ default:
|
|
|
+ return currentEventResize
|
|
|
}
|
|
|
-
|
|
|
- return newState
|
|
|
}
|
|
|
|
|
|
function reduceLoadingLevel(level: number, action): number {
|