Redirect to homepage on empty search

pull/422/head
Chocobozzz 2018-03-27 15:12:55 +02:00
parent 3e0c9ff5d5
commit fc62e39c0b
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 6 additions and 4 deletions

View File

@ -19,8 +19,6 @@ export class HeaderComponent implements OnInit {
}
doSearch () {
if (!this.searchValue) return
this.router.navigate([ '/videos', 'search' ], {
queryParams: { search: this.searchValue }
})

View File

@ -1,5 +1,6 @@
import { Component, OnDestroy, OnInit } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { RedirectService } from '@app/core'
import { immutableAssign } from '@app/shared/misc/utils'
import { NotificationsService } from 'angular2-notifications'
import { Subscription } from 'rxjs/Subscription'
@ -26,7 +27,9 @@ export class VideoSearchComponent extends AbstractVideoList implements OnInit, O
protected route: ActivatedRoute,
protected notificationsService: NotificationsService,
protected authService: AuthService,
private videoService: VideoService) {
private videoService: VideoService,
private redirectService: RedirectService
) {
super()
}
@ -36,7 +39,8 @@ export class VideoSearchComponent extends AbstractVideoList implements OnInit, O
this.subActivatedRoute = this.route.queryParams.subscribe(
queryParams => {
const querySearch = queryParams['search']
if (!querySearch || this.otherRouteParams.search === querySearch) return
if (!querySearch) return this.redirectService.redirectToHomepage()
if (this.otherRouteParams.search === querySearch) return
this.otherRouteParams.search = querySearch
this.reloadVideos()