Skip to content

Commit

Permalink
Rerender events when the timezone picker changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jancernik committed Aug 25, 2023
1 parent 23916ad commit 62e3f80
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions assets/javascripts/discourse/initializers/discourse-calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,13 @@ function initializeDiscourseCalendar(api) {
_setDynamicCalendarOptions(calendar, $calendar);
}

_setupTimezonePicker(calendar, timezone);
const resetDynamicEvents = () => {
const selectedTimezone = calendar.getOption("timeZone");
calendar.getEvents().forEach((event) => event.remove());
_setDynamicCalendarEvents(calendar, post, fullDay, selectedTimezone);
};

_setupTimezonePicker(calendar, timezone, resetDynamicEvents);
}

function attachCalendar($elem, helper) {
Expand Down Expand Up @@ -726,13 +732,14 @@ function initializeDiscourseCalendar(api) {
return defaultTimezone || currentUser?.timezone || moment.tz.guess();
}

function _setupTimezonePicker(calendar, timezone) {
function _setupTimezonePicker(calendar, timezone, resetDynamicEvents) {
const tzPicker = document.querySelector(
".discourse-calendar-timezone-picker"
);
if (tzPicker) {
tzPicker.addEventListener("change", function (event) {
calendar.setOption("timeZone", event.target.value);
resetDynamicEvents();
_insertAddToCalendarLinks(calendar);
});

Expand Down

0 comments on commit 62e3f80

Please sign in to comment.