Fix search results

pull/959/merge
Chocobozzz 2018-08-28 16:02:02 +02:00
parent c3c2ab1c8b
commit 26fabbd6d4
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 46 additions and 32 deletions

View File

@ -22,34 +22,37 @@
</div> </div>
</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 No results found
</div> </div>
<div *ngFor="let videoChannel of videoChannels" class="entry video-channel"> <ng-container *ngFor="let result of results">
<a [routerLink]="[ '/video-channels', videoChannel.nameWithHost ]"> <div *ngIf="isVideoChannel(result)" class="entry video-channel">
<img [src]="videoChannel.avatarUrl" alt="Avatar" /> <a [routerLink]="[ '/video-channels', result.nameWithHost ]">
<img [src]="result.avatarUrl" alt="Avatar" />
</a> </a>
<div class="video-channel-info"> <div class="video-channel-info">
<a [routerLink]="[ '/video-channels', videoChannel.nameWithHost ]" class="video-channel-names"> <a [routerLink]="[ '/video-channels', result.nameWithHost ]" class="video-channel-names">
<div class="video-channel-display-name">{{ videoChannel.displayName }}</div> <div class="video-channel-display-name">{{ result.displayName }}</div>
<div class="video-channel-name">{{ videoChannel.nameWithHost }}</div> <div class="video-channel-name">{{ result.nameWithHost }}</div>
</a> </a>
<div i18n class="video-channel-followers">{{ videoChannel.followersCount }} subscribers</div> <div i18n class="video-channel-followers">{{ result.followersCount }} subscribers</div>
</div> </div>
<my-subscribe-button [videoChannel]="videoChannel"></my-subscribe-button> <my-subscribe-button *ngIf="isUserLoggedIn()" [videoChannel]="result"></my-subscribe-button>
</div> </div>
<div *ngFor="let video of videos" class="entry video"> <div *ngIf="isVideo(result)" class="entry video">
<my-video-thumbnail [video]="video"></my-video-thumbnail> <my-video-thumbnail [video]="result"></my-video-thumbnail>
<div class="video-info"> <div class="video-info">
<a class="video-info-name" [routerLink]="['/videos/watch', video.uuid]" [attr.title]="video.name">{{ video.name }}</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">{{ video.publishedAt | myFromNow }} - {{ video.views | myNumberFormatter }} views</span> <span i18n class="video-info-date-views">{{ result.publishedAt | myFromNow }} - {{ result.views | myNumberFormatter }} views</span>
<a class="video-info-account" [routerLink]="[ '/accounts', video.by ]">{{ video.by }}</a> <a class="video-info-account" [routerLink]="[ '/accounts', result.by ]">{{ result.by }}</a>
</div> </div>
</div> </div>
</ng-container>
</div> </div>

View File

@ -1,16 +1,16 @@
import { Component, OnDestroy, OnInit } from '@angular/core' import { Component, OnDestroy, OnInit } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router' import { ActivatedRoute, Router } from '@angular/router'
import { RedirectService } from '@app/core' import { AuthService, RedirectService } from '@app/core'
import { NotificationsService } from 'angular2-notifications' import { NotificationsService } from 'angular2-notifications'
import { forkJoin, Subscription } from 'rxjs' import { forkJoin, Subscription } from 'rxjs'
import { SearchService } from '@app/search/search.service' import { SearchService } from '@app/search/search.service'
import { ComponentPagination } from '@app/shared/rest/component-pagination.model' import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
import { I18n } from '@ngx-translate/i18n-polyfill' import { I18n } from '@ngx-translate/i18n-polyfill'
import { Video } from '../../../../shared'
import { MetaService } from '@ngx-meta/core' import { MetaService } from '@ngx-meta/core'
import { AdvancedSearch } from '@app/search/advanced-search.model' import { AdvancedSearch } from '@app/search/advanced-search.model'
import { VideoChannel } from '@app/shared/video-channel/video-channel.model' import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
import { immutableAssign } from '@app/shared/misc/utils' import { immutableAssign } from '@app/shared/misc/utils'
import { Video } from '@app/shared/video/video.model'
@Component({ @Component({
selector: 'my-search', selector: 'my-search',
@ -18,8 +18,7 @@ import { immutableAssign } from '@app/shared/misc/utils'
templateUrl: './search.component.html' templateUrl: './search.component.html'
}) })
export class SearchComponent implements OnInit, OnDestroy { export class SearchComponent implements OnInit, OnDestroy {
videos: Video[] = [] results: (Video | VideoChannel)[] = []
videoChannels: VideoChannel[] = []
pagination: ComponentPagination = { pagination: ComponentPagination = {
currentPage: 1, currentPage: 1,
@ -42,7 +41,8 @@ export class SearchComponent implements OnInit, OnDestroy {
private metaService: MetaService, private metaService: MetaService,
private redirectService: RedirectService, private redirectService: RedirectService,
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
private searchService: SearchService private searchService: SearchService,
private authService: AuthService
) { } ) { }
ngOnInit () { ngOnInit () {
@ -79,6 +79,18 @@ export class SearchComponent implements OnInit, OnDestroy {
if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe() 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 () { search () {
forkJoin([ forkJoin([
this.searchService.searchVideos(this.currentSearch, this.pagination, this.advancedSearch), this.searchService.searchVideos(this.currentSearch, this.pagination, this.advancedSearch),
@ -86,13 +98,13 @@ export class SearchComponent implements OnInit, OnDestroy {
]) ])
.subscribe( .subscribe(
([ videosResult, videoChannelsResult ]) => { ([ 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.pagination.totalItems = videosResult.totalVideos + videoChannelsResult.total
this.videoChannels = this.videoChannels.concat(videoChannelsResult.data)
// Focus on channels // 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.resetPagination()
this.channelsPerPage = 10 this.channelsPerPage = 10
@ -126,8 +138,7 @@ export class SearchComponent implements OnInit, OnDestroy {
this.pagination.totalItems = null this.pagination.totalItems = null
this.channelsPerPage = 2 this.channelsPerPage = 2
this.videos = [] this.results = []
this.videoChannels = []
} }
private updateTitle () { private updateTitle () {