]>
Commit | Line | Data |
---|---|---|
67ed6552 C |
1 | import { forkJoin } from 'rxjs' |
2 | import { map, switchMap } from 'rxjs/operators' | |
b42f9c40 | 3 | import { Injectable } from '@angular/core' |
2989628b | 4 | import { Resolve } from '@angular/router' |
789ba349 C |
5 | import { CustomMarkupService } from '@app/shared/shared-custom-markup' |
6 | import { AboutHTML, InstanceService } from '@app/shared/shared-instance' | |
2989628b | 7 | import { About } from '@shared/models/server' |
b42f9c40 | 8 | |
789ba349 C |
9 | export type ResolverData = { |
10 | about: About | |
11 | languages: string[] | |
12 | categories: string[] | |
13 | aboutHTML: AboutHTML | |
14 | descriptionElement: HTMLDivElement | |
15 | } | |
b42f9c40 C |
16 | |
17 | @Injectable() | |
18 | export class AboutInstanceResolver implements Resolve<any> { | |
67ed6552 | 19 | |
12c8a463 | 20 | constructor ( |
789ba349 C |
21 | private instanceService: InstanceService, |
22 | private customMarkupService: CustomMarkupService | |
23 | ||
12c8a463 | 24 | ) {} |
b42f9c40 | 25 | |
2989628b | 26 | resolve () { |
b42f9c40 C |
27 | return this.instanceService.getAbout() |
28 | .pipe( | |
29 | switchMap(about => { | |
30 | return forkJoin([ | |
789ba349 | 31 | Promise.resolve(about), |
b42f9c40 | 32 | this.instanceService.buildTranslatedLanguages(about), |
789ba349 C |
33 | this.instanceService.buildTranslatedCategories(about), |
34 | this.instanceService.buildHtml(about), | |
35 | this.customMarkupService.buildElement(about.instance.description) | |
36 | ]) | |
37 | }), | |
38 | map(([ about, languages, categories, aboutHTML, { rootElement } ]) => { | |
39 | return { about, languages, categories, aboutHTML, descriptionElement: rootElement } as ResolverData | |
b42f9c40 C |
40 | }) |
41 | ) | |
42 | } | |
43 | } |