FIX: Show search context only in topic routes (#14650)

This commit is contained in:
Penar Musaraj 2021-10-20 09:48:26 -04:00 committed by GitHub
parent 3e86ec3e4e
commit 1f8939c0f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 12 deletions

View File

@ -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;