]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+accounts/accounts.component.ts
Move user moderation tool in a separate component
[github/Chocobozzz/PeerTube.git] / client / src / app / +accounts / accounts.component.ts
1 import { Component, OnInit, OnDestroy } from '@angular/core'
2 import { ActivatedRoute } from '@angular/router'
3 import { AccountService } from '@app/shared/account/account.service'
4 import { Account } from '@app/shared/account/account.model'
5 import { RestExtractor } from '@app/shared'
6 import { catchError, switchMap, distinctUntilChanged, map } from 'rxjs/operators'
7 import { Subscription } from 'rxjs'
8
9 @Component({
10 templateUrl: './accounts.component.html',
11 styleUrls: [ './accounts.component.scss' ]
12 })
13 export class AccountsComponent implements OnInit, OnDestroy {
14 account: Account
15
16 private routeSub: Subscription
17
18 constructor (
19 private route: ActivatedRoute,
20 private accountService: AccountService,
21 private restExtractor: RestExtractor
22 ) {}
23
24 ngOnInit () {
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 }
34
35 ngOnDestroy () {
36 if (this.routeSub) this.routeSub.unsubscribe()
37 }
38 }