Fix search query when updating from typeahead
This commit is contained in:
parent
f046e2fa5c
commit
7c87746e4b
|
@ -13,6 +13,7 @@ import { MetaService } from '@ngx-meta/core'
|
||||||
import { I18n } from '@ngx-translate/i18n-polyfill'
|
import { I18n } from '@ngx-translate/i18n-polyfill'
|
||||||
import { ServerConfig } from '@shared/models'
|
import { ServerConfig } from '@shared/models'
|
||||||
import { UserService } from '@app/shared'
|
import { UserService } from '@app/shared'
|
||||||
|
import { SearchTargetType } from '@shared/models/search/search-target-query.model'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-search',
|
selector: 'my-search',
|
||||||
|
@ -40,6 +41,8 @@ export class SearchComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
private channelsPerPage = 2
|
private channelsPerPage = 2
|
||||||
|
|
||||||
|
private lastSearchTarget: SearchTargetType
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private i18n: I18n,
|
private i18n: I18n,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
|
@ -63,9 +66,10 @@ export class SearchComponent implements OnInit, OnDestroy {
|
||||||
this.subActivatedRoute = this.route.queryParams.subscribe(
|
this.subActivatedRoute = this.route.queryParams.subscribe(
|
||||||
async queryParams => {
|
async queryParams => {
|
||||||
const querySearch = queryParams['search']
|
const querySearch = queryParams['search']
|
||||||
|
const searchTarget = queryParams['searchTarget']
|
||||||
|
|
||||||
// Search updated, reset filters
|
// Search updated, reset filters
|
||||||
if (this.currentSearch !== querySearch) {
|
if (this.currentSearch !== querySearch || searchTarget !== this.advancedSearch.searchTarget) {
|
||||||
this.resetPagination()
|
this.resetPagination()
|
||||||
this.advancedSearch.reset()
|
this.advancedSearch.reset()
|
||||||
|
|
||||||
|
@ -118,6 +122,7 @@ export class SearchComponent implements OnInit, OnDestroy {
|
||||||
.concat(videosResult.data)
|
.concat(videosResult.data)
|
||||||
|
|
||||||
this.pagination.totalItems = videosResult.total + videoChannelsResult.total
|
this.pagination.totalItems = videosResult.total + videoChannelsResult.total
|
||||||
|
this.lastSearchTarget = this.advancedSearch.searchTarget
|
||||||
|
|
||||||
// Focus on channels if there are no enough videos
|
// Focus on channels if there are no enough videos
|
||||||
if (this.firstSearch === true && videosResult.data.length < this.pagination.itemsPerPage) {
|
if (this.firstSearch === true && videosResult.data.length < this.pagination.itemsPerPage) {
|
||||||
|
@ -182,7 +187,7 @@ export class SearchComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
hideActions () {
|
hideActions () {
|
||||||
return this.advancedSearch.searchTarget === 'search-index'
|
return this.lastSearchTarget === 'search-index'
|
||||||
}
|
}
|
||||||
|
|
||||||
private resetPagination () {
|
private resetPagination () {
|
||||||
|
|
Loading…
Reference in New Issue