Improve videos list client performance
This commit is contained in:
parent
d466dece0a
commit
89724816ae
|
@ -11,8 +11,8 @@
|
||||||
(nearOfTop)="onNearOfTop()" (nearOfBottom)="onNearOfBottom()" (pageChanged)="onPageChanged($event)"
|
(nearOfTop)="onNearOfTop()" (nearOfBottom)="onNearOfBottom()" (pageChanged)="onPageChanged($event)"
|
||||||
class="videos" #videosElement
|
class="videos" #videosElement
|
||||||
>
|
>
|
||||||
<div *ngFor="let videos of videoPages" class="videos-page">
|
<div *ngFor="let videos of videoPages; trackBy: pageByVideoId" class="videos-page">
|
||||||
<my-video-miniature *ngFor="let video of videos" [video]="video" [user]="user" [ownerDisplayType]="ownerDisplayType"></my-video-miniature>
|
<my-video-miniature *ngFor="let video of videos; trackBy: videoById" [video]="video" [user]="user" [ownerDisplayType]="ownerDisplayType"></my-video-miniature>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -81,6 +81,15 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
|
||||||
if (this.resizeSubscription) this.resizeSubscription.unsubscribe()
|
if (this.resizeSubscription) this.resizeSubscription.unsubscribe()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pageByVideoId (index: number, page: Video[]) {
|
||||||
|
// Video are unique in all pages
|
||||||
|
return page[0].id
|
||||||
|
}
|
||||||
|
|
||||||
|
videoById (index: number, video: Video) {
|
||||||
|
return video.id
|
||||||
|
}
|
||||||
|
|
||||||
onNearOfTop () {
|
onNearOfTop () {
|
||||||
this.previousPage()
|
this.previousPage()
|
||||||
}
|
}
|
||||||
|
@ -166,7 +175,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
|
||||||
const min = this.minPageLoaded()
|
const min = this.minPageLoaded()
|
||||||
|
|
||||||
if (min > 1) {
|
if (min > 1) {
|
||||||
this.loadMoreVideos(min - 1)
|
this.loadMoreVideos(min - 1, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<div class="video-miniature">
|
<div class="video-miniature">
|
||||||
<my-video-thumbnail [video]="video" [nsfw]="isVideoBlur()"></my-video-thumbnail>
|
<my-video-thumbnail [video]="video" [nsfw]="isVideoBlur"></my-video-thumbnail>
|
||||||
|
|
||||||
<div class="video-miniature-information">
|
<div class="video-miniature-information">
|
||||||
<a
|
<a
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
class="video-miniature-name"
|
class="video-miniature-name"
|
||||||
[routerLink]="[ '/videos/watch', video.uuid ]" [attr.title]="video.name" [ngClass]="{ 'blur-filter': isVideoBlur() }"
|
[routerLink]="[ '/videos/watch', video.uuid ]" [attr.title]="video.name" [ngClass]="{ 'blur-filter': isVideoBlur }"
|
||||||
>
|
>
|
||||||
{{ video.name }}
|
{{ video.name }}
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Component, Input, OnInit } from '@angular/core'
|
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core'
|
||||||
import { User } from '../users'
|
import { User } from '../users'
|
||||||
import { Video } from './video.model'
|
import { Video } from './video.model'
|
||||||
import { ServerService } from '@app/core'
|
import { ServerService } from '@app/core'
|
||||||
|
@ -8,13 +8,16 @@ export type OwnerDisplayType = 'account' | 'videoChannel' | 'auto'
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-video-miniature',
|
selector: 'my-video-miniature',
|
||||||
styleUrls: [ './video-miniature.component.scss' ],
|
styleUrls: [ './video-miniature.component.scss' ],
|
||||||
templateUrl: './video-miniature.component.html'
|
templateUrl: './video-miniature.component.html',
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush
|
||||||
})
|
})
|
||||||
export class VideoMiniatureComponent implements OnInit {
|
export class VideoMiniatureComponent implements OnInit {
|
||||||
@Input() user: User
|
@Input() user: User
|
||||||
@Input() video: Video
|
@Input() video: Video
|
||||||
@Input() ownerDisplayType: OwnerDisplayType = 'account'
|
@Input() ownerDisplayType: OwnerDisplayType = 'account'
|
||||||
|
|
||||||
|
isVideoBlur: boolean
|
||||||
|
|
||||||
private ownerDisplayTypeChosen: 'account' | 'videoChannel'
|
private ownerDisplayTypeChosen: 'account' | 'videoChannel'
|
||||||
|
|
||||||
constructor (private serverService: ServerService) { }
|
constructor (private serverService: ServerService) { }
|
||||||
|
@ -35,10 +38,8 @@ export class VideoMiniatureComponent implements OnInit {
|
||||||
} else {
|
} else {
|
||||||
this.ownerDisplayTypeChosen = 'videoChannel'
|
this.ownerDisplayTypeChosen = 'videoChannel'
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
isVideoBlur () {
|
this.isVideoBlur = this.video.isVideoNSFWForUser(this.user, this.serverService.getConfig())
|
||||||
return this.video.isVideoNSFWForUser(this.user, this.serverService.getConfig())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
displayOwnerAccount () {
|
displayOwnerAccount () {
|
||||||
|
|
|
@ -1,11 +1,19 @@
|
||||||
import { NgModuleRef, ApplicationRef } from '@angular/core'
|
import { NgModuleRef, ApplicationRef } from '@angular/core'
|
||||||
import { createNewHosts } from '@angularclass/hmr'
|
import { createNewHosts } from '@angularclass/hmr'
|
||||||
|
import { enableDebugTools } from '@angular/platform-browser'
|
||||||
|
|
||||||
export const hmrBootstrap = (module: any, bootstrap: () => Promise<NgModuleRef<any>>) => {
|
export const hmrBootstrap = (module: any, bootstrap: () => Promise<NgModuleRef<any>>) => {
|
||||||
let ngModule: NgModuleRef<any>
|
let ngModule: NgModuleRef<any>
|
||||||
module.hot.accept()
|
module.hot.accept()
|
||||||
bootstrap()
|
bootstrap()
|
||||||
.then(mod => ngModule = mod)
|
.then(mod => {
|
||||||
|
ngModule = mod
|
||||||
|
|
||||||
|
const applicationRef = ngModule.injector.get(ApplicationRef);
|
||||||
|
const componentRef = applicationRef.components[ 0 ]
|
||||||
|
// allows to run `ng.profiler.timeChangeDetection();`
|
||||||
|
enableDebugTools(componentRef)
|
||||||
|
})
|
||||||
module.hot.dispose(() => {
|
module.hot.dispose(() => {
|
||||||
const appRef: ApplicationRef = ngModule.injector.get(ApplicationRef)
|
const appRef: ApplicationRef = ngModule.injector.get(ApplicationRef)
|
||||||
const elements = appRef.components.map(c => c.location.nativeElement)
|
const elements = appRef.components.map(c => c.location.nativeElement)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user