mirror of https://github.com/Chocobozzz/PeerTube
Fix search results
parent
c3c2ab1c8b
commit
26fabbd6d4
|
@ -22,34 +22,37 @@
|
|||
</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" />
|
||||
<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 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>
|
||||
<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>
|
||||
|
||||
<div i18n class="video-channel-followers">{{ videoChannel.followersCount }} subscribers</div>
|
||||
<div i18n class="video-channel-followers">{{ result.followersCount }} subscribers</div>
|
||||
</div>
|
||||
|
||||
<my-subscribe-button [videoChannel]="videoChannel"></my-subscribe-button>
|
||||
<my-subscribe-button *ngIf="isUserLoggedIn()" [videoChannel]="result"></my-subscribe-button>
|
||||
</div>
|
||||
|
||||
<div *ngFor="let video of videos" class="entry video">
|
||||
<my-video-thumbnail [video]="video"></my-video-thumbnail>
|
||||
<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', 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>
|
||||
<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>
|
||||
</ng-container>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
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',
|
||||
|
@ -18,8 +18,7 @@ import { immutableAssign } from '@app/shared/misc/utils'
|
|||
templateUrl: './search.component.html'
|
||||
})
|
||||
export class SearchComponent implements OnInit, OnDestroy {
|
||||
videos: Video[] = []
|
||||
videoChannels: VideoChannel[] = []
|
||||
results: (Video | VideoChannel)[] = []
|
||||
|
||||
pagination: ComponentPagination = {
|
||||
currentPage: 1,
|
||||
|
@ -42,7 +41,8 @@ export class SearchComponent implements OnInit, OnDestroy {
|
|||
private metaService: MetaService,
|
||||
private redirectService: RedirectService,
|
||||
private notificationsService: NotificationsService,
|
||||
private searchService: SearchService
|
||||
private searchService: SearchService,
|
||||
private authService: AuthService
|
||||
) { }
|
||||
|
||||
ngOnInit () {
|
||||
|
@ -79,6 +79,18 @@ export class SearchComponent implements OnInit, OnDestroy {
|
|||
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),
|
||||
|
@ -86,13 +98,13 @@ export class SearchComponent implements OnInit, OnDestroy {
|
|||
])
|
||||
.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
|
||||
|
@ -126,8 +138,7 @@ export class SearchComponent implements OnInit, OnDestroy {
|
|||
this.pagination.totalItems = null
|
||||
this.channelsPerPage = 2
|
||||
|
||||
this.videos = []
|
||||
this.videoChannels = []
|
||||
this.results = []
|
||||
}
|
||||
|
||||
private updateTitle () {
|
||||
|
|
Loading…
Reference in New Issue