Skip to content

Commit

Permalink
better args for datesDidUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Jun 10, 2020
1 parent 36af6fe commit c068e80
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
16 changes: 13 additions & 3 deletions packages/common/src/CalendarContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { EventHovering } from './interactions/EventHovering'
import { getNow } from './reducers/current-date'
import { CalendarInteraction } from './calendar-utils'
import { DelayedRunner } from './util/runner'
import { buildZonedRangeArg } from './util/date'


export interface CalendarContentProps extends CalendarData {
Expand Down Expand Up @@ -130,20 +131,29 @@ export class CalendarContent extends Component<CalendarContentProps> {
})

window.addEventListener('resize', this.handleWindowResize)

this.props.emitter.trigger('datesDidUpdate', { view: props.viewApi })
this.triggerDatesDidUpdate()
}


componentDidUpdate(prevProps: CalendarContentProps) {
let { props } = this

if (prevProps.dateProfile !== props.dateProfile) {
props.emitter.trigger('datesDidUpdate', { view: props.viewApi })
this.triggerDatesDidUpdate()
}
}


private triggerDatesDidUpdate() {
let { props } = this

props.emitter.trigger('datesDidUpdate', {
...buildZonedRangeArg(props.dateEnv, props.dateProfile.activeRange),
view: props.viewApi
})
}


componentWillUnmount() {
window.removeEventListener('resize', this.handleWindowResize)
this.resizeRunner.clear()
Expand Down
9 changes: 2 additions & 7 deletions packages/common/src/event-sources/func-event-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { EventSourceDef } from '../structs/event-source-def'
import { EventSourceError } from '../structs/event-source'
import { EventInput } from '../structs/event-parse'
import { createPlugin } from '../plugin-system'
import { buildZonedRangeArg } from '../util/date'

export type EventSourceFunc = (
arg: {
Expand Down Expand Up @@ -31,13 +32,7 @@ let eventSourceDef: EventSourceDef<EventSourceFunc> = {
let func = arg.eventSource.meta

unpromisify(
func.bind(null, { // the function returned from parseMeta
start: dateEnv.toDate(arg.range.start),
end: dateEnv.toDate(arg.range.end),
startStr: dateEnv.formatIso(arg.range.start),
endStr: dateEnv.formatIso(arg.range.end),
timeZone: dateEnv.timeZone
}),
func.bind(null, buildZonedRangeArg(dateEnv, arg.range)),
function(rawEvents) { // success
success({ rawEvents }) // needs an object response
},
Expand Down
11 changes: 11 additions & 0 deletions packages/common/src/util/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ export function diffDates(date0: DateMarker, date1: DateMarker, dateEnv: DateEnv
return diffDayAndTime(date0, date1) // returns a duration
}
}


export function buildZonedRangeArg(dateEnv: DateEnv, range: DateRange) {
return {
start: dateEnv.toDate(range.start),
end: dateEnv.toDate(range.end),
startStr: dateEnv.formatIso(range.start),
endStr: dateEnv.formatIso(range.end),
timeZone: dateEnv.timeZone
}
}

0 comments on commit c068e80

Please sign in to comment.