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

                                               

                                                                 
                                         
                                                             
                                                           
 
                                                                                                                  


                                                            
 



                                             






                                                                          


                                                                                                                              



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

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

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

  constructor (
    private instanceService: InstanceService,
    private serverService: ServerService
  ) {}

  resolve (route: ActivatedRouteSnapshot) {
    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 })))
                 })
               )
  }
}