diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-07 11:19:26 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-07 11:19:26 +0200 |
commit | 734a5ceb3d04088743d72babcb9b05e6142043f6 (patch) | |
tree | 965bfbd0bf930cf4cc9568a5dc801c4e3909a1b4 /client/src/app/+accounts/accounts.component.ts | |
parent | cc69c8db39f48b1053c246458541ccc406228711 (diff) | |
download | PeerTube-734a5ceb3d04088743d72babcb9b05e6142043f6.tar.gz PeerTube-734a5ceb3d04088743d72babcb9b05e6142043f6.tar.zst PeerTube-734a5ceb3d04088743d72babcb9b05e6142043f6.zip |
Fix account/channel pages route subscription
Diffstat (limited to 'client/src/app/+accounts/accounts.component.ts')
-rw-r--r-- | client/src/app/+accounts/accounts.component.ts | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/client/src/app/+accounts/accounts.component.ts b/client/src/app/+accounts/accounts.component.ts index 24bde61ce..2a6856c10 100644 --- a/client/src/app/+accounts/accounts.component.ts +++ b/client/src/app/+accounts/accounts.component.ts | |||
@@ -3,7 +3,8 @@ import { ActivatedRoute } from '@angular/router' | |||
3 | import { AccountService } from '@app/shared/account/account.service' | 3 | import { AccountService } from '@app/shared/account/account.service' |
4 | import { Account } from '@app/shared/account/account.model' | 4 | import { Account } from '@app/shared/account/account.model' |
5 | import { RestExtractor } from '@app/shared' | 5 | import { RestExtractor } from '@app/shared' |
6 | import { catchError } from 'rxjs/operators' | 6 | import { catchError, switchMap, distinctUntilChanged, map } from 'rxjs/operators' |
7 | import { Subscription } from 'rxjs' | ||
7 | 8 | ||
8 | @Component({ | 9 | @Component({ |
9 | templateUrl: './accounts.component.html', | 10 | templateUrl: './accounts.component.html', |
@@ -12,6 +13,8 @@ import { catchError } from 'rxjs/operators' | |||
12 | export class AccountsComponent implements OnInit { | 13 | export class AccountsComponent implements OnInit { |
13 | account: Account | 14 | account: Account |
14 | 15 | ||
16 | private routeSub: Subscription | ||
17 | |||
15 | constructor ( | 18 | constructor ( |
16 | private route: ActivatedRoute, | 19 | private route: ActivatedRoute, |
17 | private accountService: AccountService, | 20 | private accountService: AccountService, |
@@ -19,10 +22,17 @@ export class AccountsComponent implements OnInit { | |||
19 | ) {} | 22 | ) {} |
20 | 23 | ||
21 | ngOnInit () { | 24 | ngOnInit () { |
22 | const accountId = this.route.snapshot.params['accountId'] | 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 | } | ||
23 | 34 | ||
24 | this.accountService.getAccount(accountId) | 35 | ngOnDestroy () { |
25 | .pipe(catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))) | 36 | if (this.routeSub) this.routeSub.unsubscribe() |
26 | .subscribe(account => this.account = account) | ||
27 | } | 37 | } |
28 | } | 38 | } |