From 5c169487b0336d8e74305ed88db9b45a49725b2e Mon Sep 17 00:00:00 2001 From: Alteras1 Date: Wed, 12 Nov 2025 10:21:33 -0800 Subject: [PATCH 1/3] FIX: Add tracking to topic property Fixes issue where topic is null despite being navigating to topic --- .../discourse/components/custom-header-topic-button.gjs | 3 ++- spec/system/header_new_topic_button_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/javascripts/discourse/components/custom-header-topic-button.gjs b/javascripts/discourse/components/custom-header-topic-button.gjs index 41811b3..c1b65bf 100644 --- a/javascripts/discourse/components/custom-header-topic-button.gjs +++ b/javascripts/discourse/components/custom-header-topic-button.gjs @@ -1,4 +1,5 @@ import Component from "@glimmer/component"; +import { tracked } from "@glimmer/tracking"; import { action } from "@ember/object"; import { getOwner } from "@ember/owner"; import { service } from "@ember/service"; @@ -12,7 +13,7 @@ export default class CustomHeaderTopicButton extends Component { @service currentUser; @service router; - topic = this.router.currentRouteName.includes("topic") + @tracked topic = this.router.currentRouteName.includes("topic") ? getOwner(this).lookup("controller:topic") : null; diff --git a/spec/system/header_new_topic_button_spec.rb b/spec/system/header_new_topic_button_spec.rb index 60074e0..228b7e9 100644 --- a/spec/system/header_new_topic_button_spec.rb +++ b/spec/system/header_new_topic_button_spec.rb @@ -6,6 +6,7 @@ fab!(:user) { Fabricate(:user, trust_level: TrustLevel[1]) } fab!(:category) fab!(:category2, :category) + fab!(:topic) { Fabricate(:topic, category: category) } context "with logged in user" do before { sign_in(user) } @@ -23,6 +24,13 @@ expect(page).to have_css(".category-input [data-category-id='#{category2.id}']") end + it "should open the composer to the correct category when the header button is clicked from a topic page" do + visit("/t/#{topic.slug}/#{topic.id}") + find("#new-create-topic").click + + expect(page).to have_css(".category-input [data-category-id='#{category.id}']") + end + context "when new_topic_button_text is empty" do before do theme.update_setting(:new_topic_button_text, "") From ad4e7488b1f10033c313334b31dfc09f2da19190 Mon Sep 17 00:00:00 2001 From: Alteras1 Date: Wed, 12 Nov 2025 10:28:25 -0800 Subject: [PATCH 2/3] Lint fix --- .../discourse/components/custom-header-topic-button.gjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/javascripts/discourse/components/custom-header-topic-button.gjs b/javascripts/discourse/components/custom-header-topic-button.gjs index c1b65bf..0ea044b 100644 --- a/javascripts/discourse/components/custom-header-topic-button.gjs +++ b/javascripts/discourse/components/custom-header-topic-button.gjs @@ -13,7 +13,8 @@ export default class CustomHeaderTopicButton extends Component { @service currentUser; @service router; - @tracked topic = this.router.currentRouteName.includes("topic") + @tracked + topic = this.router.currentRouteName.includes("topic") ? getOwner(this).lookup("controller:topic") : null; From fce7d462ede632e59ccbda22fdd061fa3977a4fc Mon Sep 17 00:00:00 2001 From: Alteras1 Date: Wed, 12 Nov 2025 10:39:53 -0800 Subject: [PATCH 3/3] Fix spec --- spec/system/header_new_topic_button_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/system/header_new_topic_button_spec.rb b/spec/system/header_new_topic_button_spec.rb index 228b7e9..e2b66d6 100644 --- a/spec/system/header_new_topic_button_spec.rb +++ b/spec/system/header_new_topic_button_spec.rb @@ -7,6 +7,7 @@ fab!(:category) fab!(:category2, :category) fab!(:topic) { Fabricate(:topic, category: category) } + fab!(:post) { Fabricate(:post, user:, topic:) } context "with logged in user" do before { sign_in(user) } @@ -25,7 +26,7 @@ end it "should open the composer to the correct category when the header button is clicked from a topic page" do - visit("/t/#{topic.slug}/#{topic.id}") + visit(topic.url) find("#new-create-topic").click expect(page).to have_css(".category-input [data-category-id='#{category.id}']")