import { Component, OnDestroy, OnInit } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
+import { Location } from '@angular/common'
+import { RedirectService } from '@app/core'
+import { immutableAssign } from '@app/shared/misc/utils'
import { NotificationsService } from 'angular2-notifications'
-import { AbstractVideoList } from 'app/shared/video/abstract-video-list'
-import { Subscription } from 'rxjs/Subscription'
-import { SortField } from '../../shared/video/sort-field.type'
+import { Subscription } from 'rxjs'
+import { AuthService } from '../../core/auth'
+import { AbstractVideoList } from '../../shared/video/abstract-video-list'
import { VideoService } from '../../shared/video/video.service'
+import { I18n } from '@ngx-translate/i18n-polyfill'
@Component({
selector: 'my-videos-search',
templateUrl: '../../shared/video/abstract-video-list.html'
})
export class VideoSearchComponent extends AbstractVideoList implements OnInit, OnDestroy {
- titlePage = 'Search'
+ titlePage: string
currentRoute = '/videos/search'
loadOnInit = false
- private search = ''
+ protected otherRouteParams = {
+ search: ''
+ }
private subActivatedRoute: Subscription
- constructor (protected router: Router,
- protected route: ActivatedRoute,
- protected notificationsService: NotificationsService,
- private videoService: VideoService) {
+ constructor (
+ protected router: Router,
+ protected route: ActivatedRoute,
+ protected notificationsService: NotificationsService,
+ protected authService: AuthService,
+ protected location: Location,
+ protected i18n: I18n,
+ private videoService: VideoService,
+ private redirectService: RedirectService
+ ) {
super()
+
+ this.titlePage = i18n('Search')
}
ngOnInit () {
this.subActivatedRoute = this.route.queryParams.subscribe(
queryParams => {
- this.search = queryParams['search']
+ const querySearch = queryParams['search']
+
+ if (!querySearch) return this.redirectService.redirectToHomepage()
+ if (this.otherRouteParams.search === querySearch) return
+
+ this.otherRouteParams.search = querySearch
this.reloadVideos()
},
}
ngOnDestroy () {
- if (this.subActivatedRoute) {
- this.subActivatedRoute.unsubscribe()
- }
+ super.ngOnDestroy()
+
+ if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe()
+ }
+
+ getVideosObservable (page: number) {
+ const newPagination = immutableAssign(this.pagination, { currentPage: page })
+ return this.videoService.searchVideos(this.otherRouteParams.search, newPagination, this.sort)
}
- getVideosObservable () {
- return this.videoService.searchVideos(this.search, this.pagination, this.sort)
+ generateSyndicationList () {
+ throw new Error('Search does not support syndication.')
}
}