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