]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+about/about-instance/about-instance.resolver.ts
Fix menu dropdowns
[github/Chocobozzz/PeerTube.git] / client / src / app / +about / about-instance / about-instance.resolver.ts
index 9a5924ebb8d9cf11d3e49a17af85b3b35596d3ad..94388e71dcfb55b7c0affbcbd7037e9392942e33 100644 (file)
@@ -1,31 +1,67 @@
-import { forkJoin } from 'rxjs'
+import { forkJoin, Observable } from 'rxjs'
 import { map, switchMap } from 'rxjs/operators'
 import { Injectable } from '@angular/core'
-import { ActivatedRouteSnapshot, Resolve } from '@angular/router'
+import { Resolve } from '@angular/router'
 import { ServerService } from '@app/core'
-import { InstanceService } from '@app/shared/shared-instance'
-import { About, ServerConfig } from '@shared/models/server'
+import { CustomMarkupService } from '@app/shared/shared-custom-markup'
+import { AboutHTML, InstanceService } from '@app/shared/shared-instance'
+import { About, ServerStats } from '@shared/models/server'
 
-export type ResolverData = { about: About, languages: string[], categories: string[], serverConfig: ServerConfig }
+export type ResolverData = {
+  serverStats: ServerStats
+  about: About
+  languages: string[]
+  categories: string[]
+  aboutHTML: AboutHTML
+  descriptionElement: HTMLDivElement
+}
 
 @Injectable()
 export class AboutInstanceResolver implements Resolve<any> {
 
   constructor (
     private instanceService: InstanceService,
+    private customMarkupService: CustomMarkupService,
     private serverService: ServerService
   ) {}
 
-  resolve (route: ActivatedRouteSnapshot) {
+  resolve (): Observable<ResolverData> {
+    return forkJoin([
+      this.buildInstanceAboutObservable(),
+      this.buildInstanceStatsObservable()
+    ]).pipe(
+      map(([
+        [ about, languages, categories, aboutHTML, { rootElement } ],
+        serverStats
+      ]) => {
+        return {
+          serverStats,
+          about,
+          languages,
+          categories,
+          aboutHTML,
+          descriptionElement: rootElement
+        }
+      })
+    )
+  }
+
+  private buildInstanceAboutObservable () {
     return this.instanceService.getAbout()
-               .pipe(
-                 switchMap(about => {
-                   return forkJoin([
-                     this.instanceService.buildTranslatedLanguages(about),
-                     this.instanceService.buildTranslatedCategories(about),
-                     this.serverService.getConfig()
-                   ]).pipe(map(([ languages, categories, serverConfig ]) => ({ about, languages, categories, serverConfig })))
-                 })
-               )
+      .pipe(
+        switchMap(about => {
+          return forkJoin([
+            Promise.resolve(about),
+            this.instanceService.buildTranslatedLanguages(about),
+            this.instanceService.buildTranslatedCategories(about),
+            this.instanceService.buildHtml(about),
+            this.customMarkupService.buildElement(about.instance.description)
+          ])
+        })
+      )
+  }
+
+  private buildInstanceStatsObservable () {
+    return this.serverService.getServerStats()
   }
 }