aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/search/search.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-28 16:02:02 +0200
committerChocobozzz <me@florianbigard.com>2018-08-28 16:02:02 +0200
commit26fabbd6d4d5cb6c867d16ad6db6a8de0cf484ad (patch)
tree5a213c7f4ed99568ea50c6c45952e8a44acd4a8f /client/src/app/search/search.component.ts
parentc3c2ab1c8b52945df567c59118a7c77fdd6a1d4d (diff)
downloadPeerTube-26fabbd6d4d5cb6c867d16ad6db6a8de0cf484ad.tar.gz
PeerTube-26fabbd6d4d5cb6c867d16ad6db6a8de0cf484ad.tar.zst
PeerTube-26fabbd6d4d5cb6c867d16ad6db6a8de0cf484ad.zip
Fix search results
Diffstat (limited to 'client/src/app/search/search.component.ts')
-rw-r--r--client/src/app/search/search.component.ts33
1 files changed, 22 insertions, 11 deletions
diff --git a/client/src/app/search/search.component.ts b/client/src/app/search/search.component.ts
index ed84e24d9..4c540ca72 100644
--- a/client/src/app/search/search.component.ts
+++ b/client/src/app/search/search.component.ts
@@ -1,16 +1,16 @@
1import { Component, OnDestroy, OnInit } from '@angular/core' 1import { Component, OnDestroy, OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router' 2import { ActivatedRoute, Router } from '@angular/router'
3import { RedirectService } from '@app/core' 3import { AuthService, RedirectService } from '@app/core'
4import { NotificationsService } from 'angular2-notifications' 4import { NotificationsService } from 'angular2-notifications'
5import { forkJoin, Subscription } from 'rxjs' 5import { forkJoin, Subscription } from 'rxjs'
6import { SearchService } from '@app/search/search.service' 6import { SearchService } from '@app/search/search.service'
7import { ComponentPagination } from '@app/shared/rest/component-pagination.model' 7import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
8import { I18n } from '@ngx-translate/i18n-polyfill' 8import { I18n } from '@ngx-translate/i18n-polyfill'
9import { Video } from '../../../../shared'
10import { MetaService } from '@ngx-meta/core' 9import { MetaService } from '@ngx-meta/core'
11import { AdvancedSearch } from '@app/search/advanced-search.model' 10import { AdvancedSearch } from '@app/search/advanced-search.model'
12import { VideoChannel } from '@app/shared/video-channel/video-channel.model' 11import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
13import { immutableAssign } from '@app/shared/misc/utils' 12import { immutableAssign } from '@app/shared/misc/utils'
13import { Video } from '@app/shared/video/video.model'
14 14
15@Component({ 15@Component({
16 selector: 'my-search', 16 selector: 'my-search',
@@ -18,8 +18,7 @@ import { immutableAssign } from '@app/shared/misc/utils'
18 templateUrl: './search.component.html' 18 templateUrl: './search.component.html'
19}) 19})
20export class SearchComponent implements OnInit, OnDestroy { 20export class SearchComponent implements OnInit, OnDestroy {
21 videos: Video[] = [] 21 results: (Video | VideoChannel)[] = []
22 videoChannels: VideoChannel[] = []
23 22
24 pagination: ComponentPagination = { 23 pagination: ComponentPagination = {
25 currentPage: 1, 24 currentPage: 1,
@@ -42,7 +41,8 @@ export class SearchComponent implements OnInit, OnDestroy {
42 private metaService: MetaService, 41 private metaService: MetaService,
43 private redirectService: RedirectService, 42 private redirectService: RedirectService,
44 private notificationsService: NotificationsService, 43 private notificationsService: NotificationsService,
45 private searchService: SearchService 44 private searchService: SearchService,
45 private authService: AuthService
46 ) { } 46 ) { }
47 47
48 ngOnInit () { 48 ngOnInit () {
@@ -79,6 +79,18 @@ export class SearchComponent implements OnInit, OnDestroy {
79 if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe() 79 if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe()
80 } 80 }
81 81
82 isVideoChannel (d: VideoChannel | Video): d is VideoChannel {
83 return d instanceof VideoChannel
84 }
85
86 isVideo (v: VideoChannel | Video): v is Video {
87 return v instanceof Video
88 }
89
90 isUserLoggedIn () {
91 return this.authService.isLoggedIn()
92 }
93
82 search () { 94 search () {
83 forkJoin([ 95 forkJoin([
84 this.searchService.searchVideos(this.currentSearch, this.pagination, this.advancedSearch), 96 this.searchService.searchVideos(this.currentSearch, this.pagination, this.advancedSearch),
@@ -86,13 +98,13 @@ export class SearchComponent implements OnInit, OnDestroy {
86 ]) 98 ])
87 .subscribe( 99 .subscribe(
88 ([ videosResult, videoChannelsResult ]) => { 100 ([ videosResult, videoChannelsResult ]) => {
89 this.videos = this.videos.concat(videosResult.videos) 101 this.results = this.results
102 .concat(videoChannelsResult.data)
103 .concat(videosResult.videos)
90 this.pagination.totalItems = videosResult.totalVideos + videoChannelsResult.total 104 this.pagination.totalItems = videosResult.totalVideos + videoChannelsResult.total
91 105
92 this.videoChannels = this.videoChannels.concat(videoChannelsResult.data)
93
94 // Focus on channels 106 // Focus on channels
95 if (this.channelsPerPage !== 10 && this.videos.length < this.pagination.itemsPerPage) { 107 if (this.channelsPerPage !== 10 && videosResult.videos.length < this.pagination.itemsPerPage) {
96 this.resetPagination() 108 this.resetPagination()
97 109
98 this.channelsPerPage = 10 110 this.channelsPerPage = 10
@@ -126,8 +138,7 @@ export class SearchComponent implements OnInit, OnDestroy {
126 this.pagination.totalItems = null 138 this.pagination.totalItems = null
127 this.channelsPerPage = 2 139 this.channelsPerPage = 2
128 140
129 this.videos = [] 141 this.results = []
130 this.videoChannels = []
131 } 142 }
132 143
133 private updateTitle () { 144 private updateTitle () {