From e17a148b9ca4e43e74f141b5c04daad6ab211ef2 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Fri, 4 Oct 2024 07:39:50 +0900 Subject: [PATCH 1/3] FIX: shows category calendar on hot/latest The previous URL parsing code was not resilient to these paths, we now use the router to recognize these paths and extract the params we need. --- .../initializers/discourse-calendar.js | 9 +++++- spec/system/category_calendar_spec.rb | 29 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 spec/system/category_calendar_spec.rb diff --git a/assets/javascripts/discourse/initializers/discourse-calendar.js b/assets/javascripts/discourse/initializers/discourse-calendar.js index 9ea0f516d..bcacb4931 100644 --- a/assets/javascripts/discourse/initializers/discourse-calendar.js +++ b/assets/javascripts/discourse/initializers/discourse-calendar.js @@ -39,6 +39,8 @@ function initializeDiscourseCalendar(api) { const site = api.container.lookup("service:site"); const isMobileView = site && site.mobileView; + const router = api.container.lookup("service:router"); + let selector = `.${outletName}-outlet`; if (outletName === "before-topic-list-body") { selector = `.topic-list:not(.shared-drafts) .${outletName}-outlet`; @@ -59,7 +61,12 @@ function initializeDiscourseCalendar(api) { categoryEventNode.innerHTML = ""; } - const browsedCategory = Category.findBySlugPathWithID(url.split("?")[0]); + const route = router.recognize(url); + if (!route?.params?.category_slug_path_with_id) { + return; + } + + const browsedCategory = Category.findBySlugPathWithID(route.params.category_slug_path_with_id); if (!browsedCategory) { return; } diff --git a/spec/system/category_calendar_spec.rb b/spec/system/category_calendar_spec.rb new file mode 100644 index 000000000..3ab48c991 --- /dev/null +++ b/spec/system/category_calendar_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +describe "Post event", type: :system do + fab!(:admin) + fab!(:category) + + let(:category_page) { PageObjects::Pages::Category.new } + + before do + SiteSetting.calendar_enabled = true + SiteSetting.discourse_post_event_enabled = true + SiteSetting.events_calendar_categories = category.id.to_s + sign_in(admin) + end + + it "shows the calendar on the category page" do + category_page.visit(category) + + expect(category_page).to have_selector("#category-events-calendar.fc") + + find(".nav-item_hot").click + + expect(category_page).to have_selector("#category-events-calendar.fc") + + find(".nav-item_latest").click + + expect(category_page).to have_selector("#category-events-calendar.fc") + end +end From 4ac245f226abfd34211cc30ff0f5eb07fe898f2b Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Fri, 4 Oct 2024 07:41:25 +0900 Subject: [PATCH 2/3] linting --- .../javascripts/discourse/initializers/discourse-calendar.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/initializers/discourse-calendar.js b/assets/javascripts/discourse/initializers/discourse-calendar.js index bcacb4931..c22af502c 100644 --- a/assets/javascripts/discourse/initializers/discourse-calendar.js +++ b/assets/javascripts/discourse/initializers/discourse-calendar.js @@ -66,7 +66,9 @@ function initializeDiscourseCalendar(api) { return; } - const browsedCategory = Category.findBySlugPathWithID(route.params.category_slug_path_with_id); + const browsedCategory = Category.findBySlugPathWithID( + route.params.category_slug_path_with_id + ); if (!browsedCategory) { return; } From 12a07e34716659c8ed8cfc214191f56e7745bbcd Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Fri, 4 Oct 2024 11:58:29 +0900 Subject: [PATCH 3/3] Update category_calendar_spec.rb --- spec/system/category_calendar_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/category_calendar_spec.rb b/spec/system/category_calendar_spec.rb index 3ab48c991..ee1b82bbd 100644 --- a/spec/system/category_calendar_spec.rb +++ b/spec/system/category_calendar_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -describe "Post event", type: :system do +describe "Category calendar", type: :system do fab!(:admin) fab!(:category)