From ba430d7516bc5b1324b60571ba7594460969b7fb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 18 Dec 2019 15:31:54 +0100 Subject: Lazy load static objects --- client/src/app/shared/video/abstract-video-list.ts | 10 ++++++++-- client/src/app/shared/video/video-miniature.component.ts | 9 +++++++-- client/src/app/shared/video/video.service.ts | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) (limited to 'client/src/app/shared/video') diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts index 2926b179b..faeea27d9 100644 --- a/client/src/app/shared/video/abstract-video-list.ts +++ b/client/src/app/shared/video/abstract-video-list.ts @@ -13,7 +13,7 @@ import { Notifier, ServerService } from '@app/core' import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' import { I18n } from '@ngx-translate/i18n-polyfill' import { isLastMonth, isLastWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date' -import { ResultList } from '@shared/models' +import { ResultList, ServerConfig } from '@shared/models' enum GroupDate { UNKNOWN = 0, @@ -61,6 +61,8 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor onDataSubject = new Subject() + protected serverConfig: ServerConfig + protected abstract notifier: Notifier protected abstract authService: AuthService protected abstract route: ActivatedRoute @@ -85,6 +87,10 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor } ngOnInit () { + this.serverConfig = this.serverService.getTmpConfig() + this.serverService.getConfig() + .subscribe(config => this.serverConfig = config) + this.groupedDateLabels = { [GroupDate.UNKNOWN]: null, [GroupDate.TODAY]: this.i18n('Today'), @@ -251,7 +257,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor } let path = this.router.url - if (!path || path === '/') path = this.serverService.getConfig().instance.defaultClientRoute + if (!path || path === '/') path = this.serverConfig.instance.defaultClientRoute this.router.navigate([ path ], { queryParams, replaceUrl: true, queryParamsHandling: 'merge' }) } diff --git a/client/src/app/shared/video/video-miniature.component.ts b/client/src/app/shared/video/video-miniature.component.ts index d5c7dfd9b..9fffc7ddb 100644 --- a/client/src/app/shared/video/video-miniature.component.ts +++ b/client/src/app/shared/video/video-miniature.component.ts @@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Inject, Input, LOCALE import { User } from '../users' import { Video } from './video.model' import { ServerService } from '@app/core' -import { VideoPrivacy, VideoState } from '../../../../../shared' +import { ServerConfig, VideoPrivacy, VideoState } from '../../../../../shared' import { I18n } from '@ngx-translate/i18n-polyfill' import { VideoActionsDisplayType } from '@app/shared/video/video-actions-dropdown.component' import { ScreenService } from '@app/shared/misc/screen.service' @@ -55,6 +55,7 @@ export class VideoMiniatureComponent implements OnInit { report: true } showActions = false + serverConfig: ServerConfig private ownerDisplayTypeChosen: 'account' | 'videoChannel' @@ -66,10 +67,14 @@ export class VideoMiniatureComponent implements OnInit { ) { } get isVideoBlur () { - return this.video.isVideoNSFWForUser(this.user, this.serverService.getConfig()) + return this.video.isVideoNSFWForUser(this.user, this.serverConfig) } ngOnInit () { + this.serverConfig = this.serverService.getTmpConfig() + this.serverService.getConfig() + .subscribe(config => this.serverConfig = config) + this.setUpBy() // We rely on mouseenter to lazy load actions diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts index b0fa55966..9adf46495 100644 --- a/client/src/app/shared/video/video.service.ts +++ b/client/src/app/shared/video/video.service.ts @@ -64,7 +64,7 @@ export class VideoService implements VideosProvider { } getVideo (options: { videoId: string }): Observable { - return this.serverService.localeObservable + return this.serverService.getServerLocale() .pipe( switchMap(translations => { return this.authHttp.get(VideoService.BASE_VIDEO_URL + options.videoId) @@ -315,7 +315,7 @@ export class VideoService implements VideosProvider { } extractVideos (result: ResultList) { - return this.serverService.localeObservable + return this.serverService.getServerLocale() .pipe( map(translations => { const videosJson = result.data -- cgit v1.2.3