]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+accounts/accounts.component.ts
Fix account/channel pages route subscription
[github/Chocobozzz/PeerTube.git] / client / src / app / +accounts / accounts.component.ts
CommitLineData
0626e7af
C
1import { Component, OnInit } from '@angular/core'
2import { ActivatedRoute } from '@angular/router'
3import { AccountService } from '@app/shared/account/account.service'
4import { Account } from '@app/shared/account/account.model'
a51bad1a 5import { RestExtractor } from '@app/shared'
734a5ceb
C
6import { catchError, switchMap, distinctUntilChanged, map } from 'rxjs/operators'
7import { Subscription } from 'rxjs'
0626e7af
C
8
9@Component({
170726f5
C
10 templateUrl: './accounts.component.html',
11 styleUrls: [ './accounts.component.scss' ]
0626e7af 12})
170726f5 13export class AccountsComponent implements OnInit {
6b738c7a 14 account: Account
0626e7af 15
734a5ceb
C
16 private routeSub: Subscription
17
0626e7af
C
18 constructor (
19 private route: ActivatedRoute,
a51bad1a
C
20 private accountService: AccountService,
21 private restExtractor: RestExtractor
0626e7af
C
22 ) {}
23
24 ngOnInit () {
734a5ceb
C
25 this.routeSub = this.route.params
26 .pipe(
27 map(params => params[ 'accountId' ]),
28 distinctUntilChanged(),
29 switchMap(accountId => this.accountService.getAccount(accountId)),
30 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
31 )
32 .subscribe(account => this.account = account)
33 }
0626e7af 34
734a5ceb
C
35 ngOnDestroy () {
36 if (this.routeSub) this.routeSub.unsubscribe()
0626e7af 37 }
0626e7af 38}