Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: navigation when clicking on the grid on a custom week/month #5999

Merged
merged 2 commits into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
88 changes: 27 additions & 61 deletions src/components/CalendarGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
-->

<template>
<FullCalendar v-if="calendarOptions"
ref="fullCalendar"
<FullCalendar ref="fullCalendar"
:class="isWidget? 'fullcalendar-widget': ''"
:options="calendarOptions" />
:options="options" />
</template>

<script>
Expand Down Expand Up @@ -78,7 +77,7 @@
type: Boolean,
default: false,
},
url: {

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

View workflow job for this annotation

GitHub Actions / NPM lint

Prop 'url' requires default value to be set
type: String,
required: false,
},
Expand All @@ -94,8 +93,6 @@
return {
updateTodayJob: null,
updateTodayJobPreviousDate: null,
calendarOptions: null,
fullCalendarReady: false,
}
},
computed: {
Expand Down Expand Up @@ -179,7 +176,7 @@
/**
* FullCalendar Plugins
*
* @return {(PluginDef)[]}

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

View workflow job for this annotation

GitHub Actions / NPM lint

The type 'PluginDef' is undefined
*/
plugins() {
return [
Expand Down Expand Up @@ -208,38 +205,37 @@
const calendarApi = this.$refs.fullCalendar.getApi()
calendarApi.gotoDate(getYYYYMMDDFromFirstdayParam(newDate))
},
eventSources(sources, oldSources) {
const newSources = sources.filter(source => !oldSources.map(oldSource => oldSource.id).includes(source.id))
const removedSources = oldSources.filter(oldSource => !sources.map(source => source.id).includes(oldSource.id))

// Hackity hack! Unfortunately, calendarOptions.eventSources is not reactive ...
// Ref https://fullcalendar.io/docs/Calendar-addEventSource
// TODO: Find a better/safer way to prevent duplicated event sources
const calendarApi = this.$refs.fullCalendar.getApi()
for (const source of newSources) {
calendarApi.addEventSource(source)
}
const eventSources = calendarApi.getEventSources()
for (const source of removedSources) {
eventSources.find(x => x.id === source.id)?.remove()
}
},
modificationCount: debounce(function() {
const calendarApi = this.$refs.fullCalendar.getApi()
calendarApi.refetchEvents()
}, 50),
async calendarOptions(newOptions, oldOptions) {
if (!this.fullCalendarReady && newOptions && !oldOptions) {
this.fullCalendarReady = true
// Wait until the component is mounted and the ref is available
await this.$nextTick()
this.onFullCalendarReady()
}
},
},
async created() {
this.calendarOptions = await this.options
/**
* 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(() => {
const newDate = getYYYYMMDDFromFirstdayParam('now')

Expand Down Expand Up @@ -309,36 +305,6 @@
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