Skip to content

Commit

Permalink
hack for avoiding re-rendering agenda events when there are no changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bbonf committed Dec 17, 2024
1 parent 0a4183d commit 169f214
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions babex-vue/src/components/agenda/AgendaCalendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,36 @@
duration?: number,
}>();
// instead of directly using fullcalendar's url event source,
// we manually load data using the fetch api and check for changes.
// this lets us avoid re-rendering the agenda when there are no changes on the server.
function funcSource(url: string) {
let last: Array<any> | null = null;
let lastArgs: {start: string, end: string} | null = null;
return (info, success, fail) => {
let args = {start: info.startStr, end: info.endStr};
fetch(
url + '?' + new URLSearchParams(args)
).then(async response => {
let skip = false;
let data = await response.json();
if (last != null && JSON.stringify(lastArgs) == JSON.stringify(args)) {
if (JSON.stringify(last) == JSON.stringify(data)) {
skip = true;
}
}
if (!skip) {
last = data;
lastArgs = args;
success(data);
}
})
};
}
// from https://stackoverflow.com/a/64090995
function hsl2rgb(h: number, s: number, l: number): [number, number, number] {
let a = s * Math.min(l, 1 - l);
Expand Down Expand Up @@ -116,6 +146,7 @@
const showCanceled = ref<boolean>(false);
const calendarOptions: CalendarOptions = {
progressiveEventRendering: true,
plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin],
initialView: 'dayGridMonth',
customButtons: {
Expand All @@ -141,18 +172,18 @@
displayEventEnd: true,
eventSources: [
{
url: urls.agenda.feed,
events: funcSource(urls.agenda.feed),
// formatAppointment may return false, but the type signature of eventDataTransform doesn't like it
eventDataTransform: formatAppointment as any,
// syntax trick to set object property only when experiment is defined
...(props.experiment && {extraParams: {experiment: props.experiment}})
},
{
url: urls.agenda.closing,
events: funcSource(urls.agenda.closing),
eventDataTransform: formatClosing,
color: 'gray',
...(props.experiment && {extraParams: {experiment: props.experiment}})
},
}
],
eventContent: eventRender,
selectable: true,
Expand Down

0 comments on commit 169f214

Please sign in to comment.