Skip to content

A platform for community discussion. Free, open, simple.

FIX: Calendar not refreshing on navigating between categories (#36851)

Gabriel Grubbabe5e9aead99f
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjs
index fc06ede00ea..662a39844ce 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjs
@@ -151,6 +151,7 @@ export default class CategoryCalendar extends Component {
@height="650px"
@initialView={{this.categorySetting?.defaultView}}
@weekends={{this.renderWeekends}}
+ @refreshKey={{this.category.id}}
/>
{{/if}}
</template>
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/full-calendar.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/full-calendar.gjs
index 79940a66ba2..cf3fcb60e3e 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/full-calendar.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/full-calendar.gjs
@@ -168,6 +168,7 @@ export default class FullCalendar extends Component {
updateCalendar() {
if (this.calendar) {
this.calendar.setOption("headerToolbar", this.headerToolbar);
+ this.calendar.refetchEvents();
}
}
@@ -197,7 +198,12 @@ export default class FullCalendar extends Component {
<template>
<div
{{didInsert this.setupCalendar}}
- {{didUpdate this.updateCalendar @events this.capabilities.viewport.md}}
+ {{didUpdate
+ this.updateCalendar
+ @events
+ @refreshKey
+ this.capabilities.viewport.md
+ }}
{{this.forceUpdateSize}}
...attributes
>
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/post-calendar.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/post-calendar.gjs
index 9e43627be12..e769317f2e4 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/post-calendar.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/post-calendar.gjs
@@ -303,6 +303,7 @@ export default class PostCalendar extends Component {
@rightHeaderToolbar="timeGridDay,timeGridWeek,dayGridMonth,listYear"
@onLoadEvents={{this.loadEvents}}
@height={{@height}}
+ @refreshKey={{this.post.id}}
/>
</div>
</template>
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/upcoming-events-calendar.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/upcoming-events-calendar.gjs
index 8e36ad9609f..16bdbbe0b6e 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/upcoming-events-calendar.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/upcoming-events-calendar.gjs
@@ -178,6 +178,7 @@ export default class UpcomingEventsCalendar extends Component {
@leftHeaderToolbar={{this.leftHeaderToolbar}}
@centerHeaderToolbar={{this.centerHeaderToolbar}}
@rightHeaderToolbar={{this.rightHeaderToolbar}}
+ @refreshKey={{this.currentUser?.id}}
/>
</div>
</template>
diff --git a/plugins/discourse-calendar/test/javascripts/acceptance/category-calendar-navigation-test.js b/plugins/discourse-calendar/test/javascripts/acceptance/category-calendar-navigation-test.js
new file mode 100644
index 00000000000..40b81343734
--- /dev/null
+++ b/plugins/discourse-calendar/test/javascripts/acceptance/category-calendar-navigation-test.js
@@ -0,0 +1,97 @@
+import { visit } from "@ember/test-helpers";
+import { test } from "qunit";
+import { acceptance } from "discourse/tests/helpers/qunit-helpers";
+
+acceptance(
+ "Discourse Calendar - Category Events Calendar Navigation",
+ function (needs) {
+ needs.user();
+ needs.settings({
+ calendar_enabled: true,
+ discourse_post_event_enabled: true,
+ events_calendar_categories: "1|2",
+ });
+
+ let eventCalls = [];
+
+ async function assertCategory(assert, { name, id, count = 1 }) {
+ eventCalls = [];
+ await visit(`/c/${name}/${id}`);
+
+ if (count >= 1) {
+ assert.true(
+ eventCalls.some((call) => call.category_id === id),
+ `Fetched events for category ${id}`
+ );
+
+ assert.strictEqual(
+ eventCalls.length,
+ count,
+ `Only ${count} events fetch after navigation`
+ );
+
+ assert.dom(".fc-event-title").hasText(`Event in Cat ${id}`);
+ } else {
+ assert.strictEqual(
+ eventCalls.length,
+ 0,
+ `No events fetch for category ${id}`
+ );
+
+ assert.dom(".fc-event-title").doesNotExist();
+ }
+ }
+
+ needs.pretender((server, helper) => {
+ server.get("/discourse-post-event/events", (request) => {
+ eventCalls.push(request.queryParams);
+ const categoryId = request.queryParams.category_id;
+
+ return helper.response({
+ events: [
+ {
+ id: 100 + parseInt(categoryId, 10),
+ starts_at: moment().add(1, "days").toISOString(),
+ ends_at: moment().add(1, "days").add(1, "hours").toISOString(),
+ post: {
+ id: 200 + parseInt(categoryId, 10),
+ post_number: 1,
+ url: `/t/event-in-cat-${categoryId}/1/1`,
+ topic: {
+ id: 300 + parseInt(categoryId, 10),
+ title: `Event in Cat ${categoryId}`,
+ },
+ },
+ name: `Event in Cat ${categoryId}`,
+ category_id: parseInt(categoryId, 10),
+ occurrences: [
+ {
+ starts_at: moment().add(1, "days").toISOString(),
+ ends_at: moment()
+ .add(1, "days")
+ .add(1, "hours")
+ .toISOString(),
+ },
+ ],
+ },
+ ],
+ });
+ });
+ });
+
+ test("reloads events when navigating between categories", async function (assert) {
+ await assertCategory(assert, { name: "bug", id: "1" });
+ await assertCategory(assert, { name: "feature", id: "2" });
+ });
+
+ test("it does not load events for non-calendar categories", async function (assert) {
+ await assertCategory(assert, { name: "dev", id: "7", count: 0 });
+ });
+
+ test("it loads events again when returning to a calendar category", async function (assert) {
+ await assertCategory(assert, { name: "bug", id: "1" });
+ await assertCategory(assert, { name: "dev", id: "7", count: 0 });
+ await assertCategory(assert, { name: "feature", id: "2" });
+ });
+ }
+);