Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions src/themes/custom/app/search-navbar/search-navbar.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Component, Input } from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import {
FormsModule,
ReactiveFormsModule,
Expand Down Expand Up @@ -32,6 +34,7 @@ export class SearchNavbarComponent extends BaseComponent {

private localRouter: Router;
private localSearchService: SearchService;
private destroy$ = new Subject<void>();

constructor(
formBuilder: UntypedFormBuilder,
Expand All @@ -50,12 +53,22 @@ export class SearchNavbarComponent extends BaseComponent {
this.isExpanded = 'expanded';
}

const currentQuery = this.activatedRoute.snapshot.queryParams?.query;
if (currentQuery) {
this.searchForm.patchValue({
query: currentQuery
});
}
this.activatedRoute.queryParams.pipe(
takeUntil(this.destroy$)
).subscribe(params => {
const currentQuery = params?.query || '';

if (this.searchForm.get('query')?.value !== currentQuery) {
this.searchForm.patchValue({
query: currentQuery
}, { emitEvent: false });
}
});
}

ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}

/**
Expand All @@ -72,15 +85,23 @@ export class SearchNavbarComponent extends BaseComponent {

const queryParams = {
...currentParams,
query: data.query
query: data.query,
'spc.page': 1
};


const linkToNavigateTo = [this.localSearchService.getSearchLink().replace('/', '')];

if (!data.query) {
delete queryParams.query;

this.localRouter.navigateByUrl('/', { skipLocationChange: true }).then(() => {
this.localRouter.navigate(linkToNavigateTo, {
queryParams: queryParams,
});
});
return;
}

const linkToNavigateTo = [this.localSearchService.getSearchLink().replace('/', '')];

this.localRouter.navigate(linkToNavigateTo, {
queryParams: queryParams,
});
Expand Down
Loading