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/instance/instance.service.ts | 45 ++++++++++++++-------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'client/src/app/shared/instance/instance.service.ts') diff --git a/client/src/app/shared/instance/instance.service.ts b/client/src/app/shared/instance/instance.service.ts index 44b413fa4..8b26063fb 100644 --- a/client/src/app/shared/instance/instance.service.ts +++ b/client/src/app/shared/instance/instance.service.ts @@ -1,4 +1,4 @@ -import { catchError } from 'rxjs/operators' +import { catchError, map } from 'rxjs/operators' import { HttpClient } from '@angular/common/http' import { Injectable } from '@angular/core' import { environment } from '../../../environments/environment' @@ -7,6 +7,7 @@ import { About } from '../../../../../shared/models/server' import { MarkdownService } from '@app/shared/renderer' import { peertubeTranslate } from '@shared/models' import { ServerService } from '@app/core' +import { forkJoin } from 'rxjs' @Injectable() export class InstanceService { @@ -57,25 +58,35 @@ export class InstanceService { return html } - buildTranslatedLanguages (about: About, translations: any) { - const languagesArray = this.serverService.getVideoLanguages() + buildTranslatedLanguages (about: About) { + return forkJoin([ + this.serverService.getVideoLanguages(), + this.serverService.getServerLocale() + ]).pipe( + map(([ languagesArray, translations ]) => { + return about.instance.languages + .map(l => { + const languageObj = languagesArray.find(la => la.id === l) - return about.instance.languages - .map(l => { - const languageObj = languagesArray.find(la => la.id === l) - - return peertubeTranslate(languageObj.label, translations) - }) + return peertubeTranslate(languageObj.label, translations) + }) + }) + ) } - buildTranslatedCategories (about: About, translations: any) { - const categoriesArray = this.serverService.getVideoCategories() - - return about.instance.categories - .map(c => { - const categoryObj = categoriesArray.find(ca => ca.id === c) + buildTranslatedCategories (about: About) { + return forkJoin([ + this.serverService.getVideoCategories(), + this.serverService.getServerLocale() + ]).pipe( + map(([ categoriesArray, translations ]) => { + return about.instance.categories + .map(c => { + const categoryObj = categoriesArray.find(ca => ca.id === c) - return peertubeTranslate(categoryObj.label, translations) - }) + return peertubeTranslate(categoryObj.label, translations) + }) + }) + ) } } -- cgit v1.2.3