Skip to content

Commit

Permalink
Revert "fix: delay initializing the resize observer until FC is ready"
Browse files Browse the repository at this point in the history
This reverts commit a40a200.

Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
  • Loading branch information
st3iny committed May 10, 2024
1 parent 209bb44 commit a633a5a
Showing 1 changed file with 26 additions and 41 deletions.
67 changes: 26 additions & 41 deletions src/components/CalendarGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
-->

<template>
<FullCalendar v-if="options"
ref="fullCalendar"
<FullCalendar ref="fullCalendar"
:class="isWidget? 'fullcalendar-widget': ''"
:options="options" />
</template>
Expand Down Expand Up @@ -94,7 +93,6 @@ export default {
return {
updateTodayJob: null,
updateTodayJobPreviousDate: null,
fullCalendarReady: false,
}
},
computed: {
Expand Down Expand Up @@ -211,14 +209,31 @@ export default {
const calendarApi = this.$refs.fullCalendar.getApi()
calendarApi.refetchEvents()
}, 50),
async options(newOptions) {
if (!this.fullCalendarReady && newOptions) {
this.fullCalendarReady = true
// Wait until the component is mounted and the ref is available
await this.$nextTick()
this.onFullCalendarReady()
}
},
},
/**
* FullCalendar 5 is using calculated px values for the width
* of its views.
* Hence a simple `width: 100%` won't assure that the calendar-grid
* is always using the full available width.
*

Check warning on line 218 in src/components/CalendarGrid.vue

View check run for this annotation

Codecov / codecov/patch

src/components/CalendarGrid.vue#L218

Added line #L218 was not covered by tests
* Toggling the AppNavigation or AppSidebar will change the amount
* of available space, but it will not be covered by the window
* resize event, because the actual window size did not change.

Check warning on line 221 in src/components/CalendarGrid.vue

View check run for this annotation

Codecov / codecov/patch

src/components/CalendarGrid.vue#L220-L221

Added lines #L220 - L221 were not covered by tests
*
* To make sure, that the calendar-grid is always using all space,

Check warning on line 223 in src/components/CalendarGrid.vue

View check run for this annotation

Codecov / codecov/patch

src/components/CalendarGrid.vue#L223

Added line #L223 was not covered by tests
* we have to register a resize-observer here, that will automatically
* update the fullCalendar size, when the available space changes.
*/
mounted() {
if (window.ResizeObserver) {

Check warning on line 228 in src/components/CalendarGrid.vue

View check run for this annotation

Codecov / codecov/patch

src/components/CalendarGrid.vue#L226-L228

Added lines #L226 - L228 were not covered by tests
const resizeObserver = new ResizeObserver(debounce(() => {
this.$refs.fullCalendar
.getApi()

Check warning on line 231 in src/components/CalendarGrid.vue

View check run for this annotation

Codecov / codecov/patch

src/components/CalendarGrid.vue#L230-L231

Added lines #L230 - L231 were not covered by tests
.updateSize()
}, 100))
resizeObserver.observe(this.$refs.fullCalendar.$el)
}

Check warning on line 236 in src/components/CalendarGrid.vue

View check run for this annotation

Codecov / codecov/patch

src/components/CalendarGrid.vue#L235-L236

Added lines #L235 - L236 were not covered by tests
},
async created() {
this.updateTodayJob = setInterval(() => {
Expand Down Expand Up @@ -290,36 +305,6 @@ export default {
this.$store.dispatch('setInitialView', { initialView })
}
}, 5000),
/**
* Called once when FullCalendar is ready. This event is delayed until the component is
* mounted and its ref is available.
*/
onFullCalendarReady() {
/**
* FullCalendar 5 is using calculated px values for the width
* of its views.
* Hence a simple `width: 100%` won't assure that the calendar-grid
* is always using the full available width.
*
* Toggling the AppNavigation or AppSidebar will change the amount
* of available space, but it will not be covered by the window
* resize event, because the actual window size did not change.
*
* To make sure, that the calendar-grid is always using all space,
* we have to register a resize-observer here, that will automatically
* update the fullCalendar size, when the available space changes.
*/
if (window.ResizeObserver) {
const resizeObserver = new ResizeObserver(debounce(() => {
this.$refs.fullCalendar
.getApi()
.updateSize()
}, 100))
resizeObserver.observe(this.$refs.fullCalendar.$el)
}
},
},
}
</script>
Expand Down

0 comments on commit a633a5a

Please sign in to comment.