|
| 1 | +import { Component } from '@angular/core'; |
| 2 | +import { ActivatedRoute } from '@angular/router'; |
| 3 | +import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; |
| 4 | +import { map, pluck, switchMap, switchMapTo } from 'rxjs/operators'; |
| 5 | +import { InformationType } from 'src/app/services/data/information/information'; |
| 6 | +import { InformationRepository } from 'src/app/services/data/information/information-repository.service'; |
| 7 | +import { ProofRepository } from 'src/app/services/data/proof/proof-repository.service'; |
| 8 | +import { isNonNullable } from 'src/app/utils/rx-operators'; |
| 9 | + |
| 10 | +@UntilDestroy({ checkProperties: true }) |
| 11 | +@Component({ |
| 12 | + selector: 'app-information', |
| 13 | + templateUrl: './information.page.html', |
| 14 | + styleUrls: ['./information.page.scss'], |
| 15 | +}) |
| 16 | +export class InformationPage { |
| 17 | + |
| 18 | + readonly proof$ = this.route.paramMap.pipe( |
| 19 | + map(params => params.get('hash')), |
| 20 | + isNonNullable(), |
| 21 | + switchMap(hash => this.proofRepository.getByHash$(hash)), |
| 22 | + isNonNullable() |
| 23 | + ); |
| 24 | + |
| 25 | + readonly hash$ = this.proof$.pipe(pluck('hash')); |
| 26 | + |
| 27 | + readonly locationInformation$ = this.proof$.pipe( |
| 28 | + switchMap(proof => this.informationRepository.getByProof$(proof)), |
| 29 | + map(informationList => informationList.filter(information => information.type === InformationType.Location)) |
| 30 | + ); |
| 31 | + |
| 32 | + readonly otherInformation$ = this.proof$.pipe( |
| 33 | + switchMap(proof => this.informationRepository.getByProof$(proof)), |
| 34 | + map(informationList => informationList.filter(information => information.type === InformationType.Other)) |
| 35 | + ); |
| 36 | + |
| 37 | + readonly deviceInformation$ = this.proof$.pipe( |
| 38 | + switchMap(proof => this.informationRepository.getByProof$(proof)), |
| 39 | + map(informationList => informationList.filter(information => information.type === InformationType.Device)) |
| 40 | + ); |
| 41 | + |
| 42 | + constructor( |
| 43 | + private readonly route: ActivatedRoute, |
| 44 | + private readonly proofRepository: ProofRepository, |
| 45 | + private readonly informationRepository: InformationRepository, |
| 46 | + ) { } |
| 47 | + |
| 48 | + ionViewWillEnter() { |
| 49 | + this.proofRepository.refresh$().pipe( |
| 50 | + switchMapTo(this.informationRepository.refresh$()), |
| 51 | + untilDestroyed(this) |
| 52 | + ).subscribe(); |
| 53 | + } |
| 54 | +} |
0 commit comments