Skip to content

Commit

Permalink
fix(calendar): prevent redundant range updates (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomosterlund committed Apr 30, 2024
1 parent 5e9b6e7 commit fbdd100
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ describe('calendar state', () => {
end: '2023-09-13 23:59',
})
})

it('should not update the range if both start and end remain the same', () => {
const state = createCalendarState(config, timeUnitsImpl)
state.view.value = InternalViewName.Day
state.range.value = {
start: '2023-09-13 00:00',
end: '2023-09-13 23:59',
}
const originalRange = state.range.value

state.handleDateSelection('2023-09-13')

expect(state.range.value).toBe(originalRange) // checking object equality is wanted here
})
})

describe('setting the range in a hybrid day', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,19 @@ export const createCalendarState = (
const selectedView = calendarConfig.views.find(
(availableView) => availableView.name === view.value
)
range.value = (selectedView as View).setDateRange({
const newRange = (selectedView as View).setDateRange({
calendarConfig,
date,
range,
timeUnitsImpl,
})
if (
newRange.start === range.value?.start &&
newRange.end === range.value?.end
)
return

range.value = newRange
}

const isCalendarSmall = signal<boolean | undefined>(undefined)
Expand Down

0 comments on commit fbdd100

Please sign in to comment.