Use template-bound autorun in wekan-fullcalendar to prevent Blaze current view errors

This commit is contained in:
Harry Adel 2026-02-24 23:43:53 +02:00
parent 2fe490ec3d
commit 8dafc774d8

View file

@ -1,5 +1,4 @@
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import { Tracker } from 'meteor/tracker';
const FullCalendarCore = require('@fullcalendar/core/main.cjs.js'); const FullCalendarCore = require('@fullcalendar/core/main.cjs.js');
const FullCalendarDayGrid = require('@fullcalendar/daygrid/main.cjs.js'); const FullCalendarDayGrid = require('@fullcalendar/daygrid/main.cjs.js');
@ -9,9 +8,10 @@ const FullCalendarTimeGrid = require('@fullcalendar/timegrid/main.cjs.js');
const FullCalendarLocalesAll = require('@fullcalendar/core/locales-all.js'); const FullCalendarLocalesAll = require('@fullcalendar/core/locales-all.js');
Template.fullcalendar.onRendered(function () { Template.fullcalendar.onRendered(function () {
const instance = this;
const container = this.find('div'); const container = this.find('div');
this.autorunHandle = Tracker.autorun(() => { this.autorunHandle = this.autorun(() => {
const data = Template.currentData() || {}; const data = Template.currentData() || {};
let preservedViewType = null; let preservedViewType = null;
let preservedDate = null; let preservedDate = null;
@ -39,16 +39,16 @@ Template.fullcalendar.onRendered(function () {
options.locales = FullCalendarLocalesAll.default; options.locales = FullCalendarLocalesAll.default;
} }
if (this.calendar) { if (instance.calendar) {
// Keep the user's current view/date when reactive data updates. // Keep the user's current view/date when reactive data updates.
if (this.calendar.view && this.calendar.view.type) { if (instance.calendar.view && instance.calendar.view.type) {
preservedViewType = this.calendar.view.type; preservedViewType = instance.calendar.view.type;
} }
if (this.calendar.getDate) { if (instance.calendar.getDate) {
preservedDate = this.calendar.getDate(); preservedDate = instance.calendar.getDate();
} }
this.calendar.destroy(); instance.calendar.destroy();
this.calendar = null; instance.calendar = null;
} }
if (preservedViewType && !options.initialView) { if (preservedViewType && !options.initialView) {
@ -58,7 +58,7 @@ Template.fullcalendar.onRendered(function () {
options.initialDate = preservedDate; options.initialDate = preservedDate;
} }
this.calendar = new FullCalendarCore.Calendar(container, { instance.calendar = new FullCalendarCore.Calendar(container, {
plugins: [ plugins: [
FullCalendarDayGrid.default, FullCalendarDayGrid.default,
FullCalendarInteraction.default, FullCalendarInteraction.default,
@ -69,8 +69,8 @@ Template.fullcalendar.onRendered(function () {
}); });
// Allow callers to manually access and refetch without jQuery plugin API. // Allow callers to manually access and refetch without jQuery plugin API.
container._wekanCalendar = this.calendar; container._wekanCalendar = instance.calendar;
this.calendar.render(); instance.calendar.render();
}); });
}); });