diff options
author | Chocobozzz <me@florianbigard.com> | 2018-05-09 09:26:41 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-05-09 09:32:26 +0200 |
commit | 62e62f118d5da57acd3494fece2e8ed357564ffe (patch) | |
tree | ff5b7c6ec5708d71a76a2eb5744d810015ae29a5 /client/src/app/+my-account/my-account-video-channels/my-account-video-channels.component.ts | |
parent | 1952a538baa330b13bd11631b3975f7ef1c37e70 (diff) | |
download | PeerTube-62e62f118d5da57acd3494fece2e8ed357564ffe.tar.gz PeerTube-62e62f118d5da57acd3494fece2e8ed357564ffe.tar.zst PeerTube-62e62f118d5da57acd3494fece2e8ed357564ffe.zip |
Load my-account module lazily
Diffstat (limited to 'client/src/app/+my-account/my-account-video-channels/my-account-video-channels.component.ts')
-rw-r--r-- | client/src/app/+my-account/my-account-video-channels/my-account-video-channels.component.ts | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/client/src/app/+my-account/my-account-video-channels/my-account-video-channels.component.ts b/client/src/app/+my-account/my-account-video-channels/my-account-video-channels.component.ts new file mode 100644 index 000000000..eeaca11df --- /dev/null +++ b/client/src/app/+my-account/my-account-video-channels/my-account-video-channels.component.ts | |||
@@ -0,0 +1,59 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | ||
2 | import { NotificationsService } from 'angular2-notifications' | ||
3 | import 'rxjs/add/observable/from' | ||
4 | import 'rxjs/add/operator/concatAll' | ||
5 | import { AuthService } from '../../core/auth' | ||
6 | import { ConfirmService } from '../../core/confirm' | ||
7 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | ||
8 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' | ||
9 | import { User } from '@app/shared' | ||
10 | |||
11 | @Component({ | ||
12 | selector: 'my-account-video-channels', | ||
13 | templateUrl: './my-account-video-channels.component.html', | ||
14 | styleUrls: [ './my-account-video-channels.component.scss' ] | ||
15 | }) | ||
16 | export class MyAccountVideoChannelsComponent implements OnInit { | ||
17 | videoChannels: VideoChannel[] = [] | ||
18 | |||
19 | private user: User | ||
20 | |||
21 | constructor ( | ||
22 | private authService: AuthService, | ||
23 | private notificationsService: NotificationsService, | ||
24 | private confirmService: ConfirmService, | ||
25 | private videoChannelService: VideoChannelService | ||
26 | ) {} | ||
27 | |||
28 | ngOnInit () { | ||
29 | this.user = this.authService.getUser() | ||
30 | |||
31 | this.loadVideoChannels() | ||
32 | } | ||
33 | |||
34 | async deleteVideoChannel (videoChannel: VideoChannel) { | ||
35 | const res = await this.confirmService.confirmWithInput( | ||
36 | `Do you really want to delete ${videoChannel.displayName}? It will delete all videos uploaded in this channel too.`, | ||
37 | 'Please type the name of the video channel to confirm', | ||
38 | videoChannel.displayName, | ||
39 | 'Delete' | ||
40 | ) | ||
41 | if (res === false) return | ||
42 | |||
43 | this.videoChannelService.removeVideoChannel(videoChannel) | ||
44 | .subscribe( | ||
45 | status => { | ||
46 | this.loadVideoChannels() | ||
47 | this.notificationsService.success('Success', `Video channel ${videoChannel.name} deleted.`) | ||
48 | }, | ||
49 | |||
50 | error => this.notificationsService.error('Error', error.message) | ||
51 | ) | ||
52 | } | ||
53 | |||
54 | private loadVideoChannels () { | ||
55 | this.authService.userInformationLoaded | ||
56 | .flatMap(() => this.videoChannelService.listAccountVideoChannels(this.user.account.id)) | ||
57 | .subscribe(res => this.videoChannels = res.data) | ||
58 | } | ||
59 | } | ||