X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Baccounts%2Faccounts.component.ts;h=af0451e910099d3627c22b9329bc24bf1042f953;hb=9a0fc8409c7a783348ec212fa9f38d0a98413467;hp=24bde61ce1ef53701c67e460db0bf5d590ce035f;hpb=a51bad1accfade25916db0dadaeb879a182cf19b;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+accounts/accounts.component.ts b/client/src/app/+accounts/accounts.component.ts index 24bde61ce..af0451e91 100644 --- a/client/src/app/+accounts/accounts.component.ts +++ b/client/src/app/+accounts/accounts.component.ts @@ -1,17 +1,20 @@ -import { Component, OnInit } from '@angular/core' +import { Component, OnInit, OnDestroy } from '@angular/core' import { ActivatedRoute } from '@angular/router' import { AccountService } from '@app/shared/account/account.service' import { Account } from '@app/shared/account/account.model' import { RestExtractor } from '@app/shared' -import { catchError } from 'rxjs/operators' +import { catchError, switchMap, distinctUntilChanged, map } from 'rxjs/operators' +import { Subscription } from 'rxjs' @Component({ templateUrl: './accounts.component.html', styleUrls: [ './accounts.component.scss' ] }) -export class AccountsComponent implements OnInit { +export class AccountsComponent implements OnInit, OnDestroy { account: Account + private routeSub: Subscription + constructor ( private route: ActivatedRoute, private accountService: AccountService, @@ -19,10 +22,17 @@ export class AccountsComponent implements OnInit { ) {} ngOnInit () { - const accountId = this.route.snapshot.params['accountId'] + this.routeSub = this.route.params + .pipe( + map(params => params[ 'accountId' ]), + distinctUntilChanged(), + switchMap(accountId => this.accountService.getAccount(accountId)), + catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ])) + ) + .subscribe(account => this.account = account) + } - this.accountService.getAccount(accountId) - .pipe(catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))) - .subscribe(account => this.account = account) + ngOnDestroy () { + if (this.routeSub) this.routeSub.unsubscribe() } }