aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/app/+about/about-instance/about-instance.resolver.ts
blob: ee0219df0cfa36f1676d09fc09729d30aae59668 (plain) (tree)
1
2
3
4
5
6
7
8

                                               
                                          
                                         
                                                             
                                             
 
                                                                                      


                                                            
 
               
                                            
      
 
              




                                                                          

                                                                                                                  



                   
import { forkJoin } from 'rxjs'
import { map, switchMap } from 'rxjs/operators'
import { Injectable } from '@angular/core'
import { Resolve } from '@angular/router'
import { InstanceService } from '@app/shared/shared-instance'
import { About } from '@shared/models/server'

export type ResolverData = { about: About, languages: string[], categories: string[] }

@Injectable()
export class AboutInstanceResolver implements Resolve<any> {

  constructor (
    private instanceService: InstanceService
  ) {}

  resolve () {
    return this.instanceService.getAbout()
               .pipe(
                 switchMap(about => {
                   return forkJoin([
                     this.instanceService.buildTranslatedLanguages(about),
                     this.instanceService.buildTranslatedCategories(about)
                   ]).pipe(map(([ languages, categories ]) => ({ about, languages, categories }) as ResolverData))
                 })
               )
  }
}