A platform for community discussion. Free, open, simple.
FIX: Show search context only in topic routes (#14650)
Penar Musaraj1f8939c0f130
diff --git a/app/assets/javascripts/discourse/app/widgets/header.js b/app/assets/javascripts/discourse/app/widgets/header.jsindex e92f8ac2985..8adbe4d533c 100644--- a/app/assets/javascripts/discourse/app/widgets/header.js+++ b/app/assets/javascripts/discourse/app/widgets/header.js@@ -347,6 +347,12 @@ export default createWidget("header", {},html(attrs, state) {+ let inTopicRoute = false;++ if (this.state.inTopicContext) {+ inTopicRoute = this.router.currentRouteName.startsWith("topic.");+ }+let contents = () => {const headerIcons = this.attach("header-icons", {hamburgerVisible: state.hamburgerVisible,@@ -366,7 +372,7 @@ export default createWidget("header", {if (state.searchVisible) {panels.push(this.attach("search-menu", {- inTopicContext: state.inTopicContext,+ inTopicContext: state.inTopicContext && inTopicRoute,}));} else if (state.hamburgerVisible) {@@ -449,9 +455,7 @@ export default createWidget("header", {params = `?context=${context.type}&context_id=${context.id}&skip_context=${this.state.skipSearchContext}`;}- const currentPath = this.router.get("_router.currentPath");-- if (currentPath === "full-page-search") {+ if (this.router.currentRouteName === "full-page-search") {scrollTop();$(".full-page-search").focus();return false;@@ -524,16 +528,10 @@ export default createWidget("header", {const { state } = this;state.inTopicContext = false;- const currentPath = this.router.get("_router.currentPath");- const blocklist = [/^discovery\.categories/];- const allowlist = [/^topic\./];- const check = function (regex) {- return !!currentPath.match(regex);- };- let showSearch = allowlist.any(check) && !blocklist.any(check);+ let showSearch = this.router.currentRouteName.startsWith("topic.");// If we're viewing a topic, only intercept search if there are cloaked posts- if (showSearch && currentPath.match(/^topic\./)) {+ if (showSearch) {const controller = this.register.lookup("controller:topic");const total = controller.get("model.postStream.stream.length") || 0;const chunkSize = controller.get("model.chunk_size") || 0;