</div>
</div>
- <div i18n *ngIf="pagination.totalItems === 0 && videoChannels.length === 0" class="no-result">
+ <div i18n *ngIf="pagination.totalItems === 0 && results.length === 0" class="no-result">
No results found
</div>
- <div *ngFor="let videoChannel of videoChannels" class="entry video-channel">
- <a [routerLink]="[ '/video-channels', videoChannel.nameWithHost ]">
- <img [src]="videoChannel.avatarUrl" alt="Avatar" />
- </a>
-
- <div class="video-channel-info">
- <a [routerLink]="[ '/video-channels', videoChannel.nameWithHost ]" class="video-channel-names">
- <div class="video-channel-display-name">{{ videoChannel.displayName }}</div>
- <div class="video-channel-name">{{ videoChannel.nameWithHost }}</div>
+ <ng-container *ngFor="let result of results">
+ <div *ngIf="isVideoChannel(result)" class="entry video-channel">
+ <a [routerLink]="[ '/video-channels', result.nameWithHost ]">
+ <img [src]="result.avatarUrl" alt="Avatar" />
</a>
- <div i18n class="video-channel-followers">{{ videoChannel.followersCount }} subscribers</div>
- </div>
+ <div class="video-channel-info">
+ <a [routerLink]="[ '/video-channels', result.nameWithHost ]" class="video-channel-names">
+ <div class="video-channel-display-name">{{ result.displayName }}</div>
+ <div class="video-channel-name">{{ result.nameWithHost }}</div>
+ </a>
- <my-subscribe-button [videoChannel]="videoChannel"></my-subscribe-button>
- </div>
+ <div i18n class="video-channel-followers">{{ result.followersCount }} subscribers</div>
+ </div>
- <div *ngFor="let video of videos" class="entry video">
- <my-video-thumbnail [video]="video"></my-video-thumbnail>
+ <my-subscribe-button *ngIf="isUserLoggedIn()" [videoChannel]="result"></my-subscribe-button>
+ </div>
- <div class="video-info">
- <a class="video-info-name" [routerLink]="['/videos/watch', video.uuid]" [attr.title]="video.name">{{ video.name }}</a>
- <span i18n class="video-info-date-views">{{ video.publishedAt | myFromNow }} - {{ video.views | myNumberFormatter }} views</span>
- <a class="video-info-account" [routerLink]="[ '/accounts', video.by ]">{{ video.by }}</a>
+ <div *ngIf="isVideo(result)" class="entry video">
+ <my-video-thumbnail [video]="result"></my-video-thumbnail>
+
+ <div class="video-info">
+ <a class="video-info-name" [routerLink]="['/videos/watch', result.uuid]" [attr.title]="result.name">{{ result.name }}</a>
+ <span i18n class="video-info-date-views">{{ result.publishedAt | myFromNow }} - {{ result.views | myNumberFormatter }} views</span>
+ <a class="video-info-account" [routerLink]="[ '/accounts', result.by ]">{{ result.by }}</a>
+ </div>
</div>
- </div>
+ </ng-container>
+
</div>
import { Component, OnDestroy, OnInit } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
-import { RedirectService } from '@app/core'
+import { AuthService, RedirectService } from '@app/core'
import { NotificationsService } from 'angular2-notifications'
import { forkJoin, Subscription } from 'rxjs'
import { SearchService } from '@app/search/search.service'
import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
import { I18n } from '@ngx-translate/i18n-polyfill'
-import { Video } from '../../../../shared'
import { MetaService } from '@ngx-meta/core'
import { AdvancedSearch } from '@app/search/advanced-search.model'
import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
import { immutableAssign } from '@app/shared/misc/utils'
+import { Video } from '@app/shared/video/video.model'
@Component({
selector: 'my-search',
templateUrl: './search.component.html'
})
export class SearchComponent implements OnInit, OnDestroy {
- videos: Video[] = []
- videoChannels: VideoChannel[] = []
+ results: (Video | VideoChannel)[] = []
pagination: ComponentPagination = {
currentPage: 1,
private metaService: MetaService,
private redirectService: RedirectService,
private notificationsService: NotificationsService,
- private searchService: SearchService
+ private searchService: SearchService,
+ private authService: AuthService
) { }
ngOnInit () {
if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe()
}
+ isVideoChannel (d: VideoChannel | Video): d is VideoChannel {
+ return d instanceof VideoChannel
+ }
+
+ isVideo (v: VideoChannel | Video): v is Video {
+ return v instanceof Video
+ }
+
+ isUserLoggedIn () {
+ return this.authService.isLoggedIn()
+ }
+
search () {
forkJoin([
this.searchService.searchVideos(this.currentSearch, this.pagination, this.advancedSearch),
])
.subscribe(
([ videosResult, videoChannelsResult ]) => {
- this.videos = this.videos.concat(videosResult.videos)
+ this.results = this.results
+ .concat(videoChannelsResult.data)
+ .concat(videosResult.videos)
this.pagination.totalItems = videosResult.totalVideos + videoChannelsResult.total
- this.videoChannels = this.videoChannels.concat(videoChannelsResult.data)
-
// Focus on channels
- if (this.channelsPerPage !== 10 && this.videos.length < this.pagination.itemsPerPage) {
+ if (this.channelsPerPage !== 10 && videosResult.videos.length < this.pagination.itemsPerPage) {
this.resetPagination()
this.channelsPerPage = 10
this.pagination.totalItems = null
this.channelsPerPage = 2
- this.videos = []
- this.videoChannels = []
+ this.results = []
}
private updateTitle () {