]>
Commit | Line | Data |
---|---|---|
1 | import { Component, OnDestroy, OnInit } from '@angular/core' | |
2 | import { ActivatedRoute } from '@angular/router' | |
3 | import { Account } from '@app/shared/account/account.model' | |
4 | import { AccountService } from '@app/shared/account/account.service' | |
5 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' | |
6 | import { flatMap, map, tap } from 'rxjs/operators' | |
7 | import { Subscription } from 'rxjs' | |
8 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | |
9 | ||
10 | @Component({ | |
11 | selector: 'my-account-video-channels', | |
12 | templateUrl: './account-video-channels.component.html', | |
13 | styleUrls: [ './account-video-channels.component.scss' ] | |
14 | }) | |
15 | export class AccountVideoChannelsComponent implements OnInit, OnDestroy { | |
16 | account: Account | |
17 | videoChannels: VideoChannel[] = [] | |
18 | ||
19 | private accountSub: Subscription | |
20 | ||
21 | constructor ( | |
22 | protected route: ActivatedRoute, | |
23 | private accountService: AccountService, | |
24 | private videoChannelService: VideoChannelService | |
25 | ) { } | |
26 | ||
27 | ngOnInit () { | |
28 | // Parent get the account for us | |
29 | this.accountSub = this.accountService.accountLoaded | |
30 | .pipe( | |
31 | tap(account => this.account = account), | |
32 | flatMap(account => this.videoChannelService.listAccountVideoChannels(account)), | |
33 | map(res => res.data) | |
34 | ) | |
35 | .subscribe(videoChannels => this.videoChannels = videoChannels) | |
36 | } | |
37 | ||
38 | ngOnDestroy () { | |
39 | if (this.accountSub) this.accountSub.unsubscribe() | |
40 | } | |
41 | } |