mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Show search context only in topic routes (#14650)
This commit is contained in:
parent
3e86ec3e4e
commit
1f8939c0f1
@ -347,6 +347,12 @@ export default createWidget("header", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
html(attrs, state) {
|
html(attrs, state) {
|
||||||
|
let inTopicRoute = false;
|
||||||
|
|
||||||
|
if (this.state.inTopicContext) {
|
||||||
|
inTopicRoute = this.router.currentRouteName.startsWith("topic.");
|
||||||
|
}
|
||||||
|
|
||||||
let contents = () => {
|
let contents = () => {
|
||||||
const headerIcons = this.attach("header-icons", {
|
const headerIcons = this.attach("header-icons", {
|
||||||
hamburgerVisible: state.hamburgerVisible,
|
hamburgerVisible: state.hamburgerVisible,
|
||||||
@ -366,7 +372,7 @@ export default createWidget("header", {
|
|||||||
if (state.searchVisible) {
|
if (state.searchVisible) {
|
||||||
panels.push(
|
panels.push(
|
||||||
this.attach("search-menu", {
|
this.attach("search-menu", {
|
||||||
inTopicContext: state.inTopicContext,
|
inTopicContext: state.inTopicContext && inTopicRoute,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
} else if (state.hamburgerVisible) {
|
} 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}`;
|
params = `?context=${context.type}&context_id=${context.id}&skip_context=${this.state.skipSearchContext}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentPath = this.router.get("_router.currentPath");
|
if (this.router.currentRouteName === "full-page-search") {
|
||||||
|
|
||||||
if (currentPath === "full-page-search") {
|
|
||||||
scrollTop();
|
scrollTop();
|
||||||
$(".full-page-search").focus();
|
$(".full-page-search").focus();
|
||||||
return false;
|
return false;
|
||||||
@ -524,16 +528,10 @@ export default createWidget("header", {
|
|||||||
const { state } = this;
|
const { state } = this;
|
||||||
state.inTopicContext = false;
|
state.inTopicContext = false;
|
||||||
|
|
||||||
const currentPath = this.router.get("_router.currentPath");
|
let showSearch = this.router.currentRouteName.startsWith("topic.");
|
||||||
const blocklist = [/^discovery\.categories/];
|
|
||||||
const allowlist = [/^topic\./];
|
|
||||||
const check = function (regex) {
|
|
||||||
return !!currentPath.match(regex);
|
|
||||||
};
|
|
||||||
let showSearch = allowlist.any(check) && !blocklist.any(check);
|
|
||||||
|
|
||||||
// If we're viewing a topic, only intercept search if there are cloaked posts
|
// 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 controller = this.register.lookup("controller:topic");
|
||||||
const total = controller.get("model.postStream.stream.length") || 0;
|
const total = controller.get("model.postStream.stream.length") || 0;
|
||||||
const chunkSize = controller.get("model.chunk_size") || 0;
|
const chunkSize = controller.get("model.chunk_size") || 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user