1 import { Component, OnInit } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { AuthService } from '../../core/auth'
4 import { ConfirmService } from '../../core/confirm'
5 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
6 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
7 import { User } from '@app/shared'
8 import { flatMap } from 'rxjs/operators'
11 selector: 'my-account-video-channels',
12 templateUrl: './my-account-video-channels.component.html',
13 styleUrls: [ './my-account-video-channels.component.scss' ]
15 export class MyAccountVideoChannelsComponent implements OnInit {
16 videoChannels: VideoChannel[] = []
21 private authService: AuthService,
22 private notificationsService: NotificationsService,
23 private confirmService: ConfirmService,
24 private videoChannelService: VideoChannelService
28 this.user = this.authService.getUser()
30 this.loadVideoChannels()
33 async deleteVideoChannel (videoChannel: VideoChannel) {
34 const res = await this.confirmService.confirmWithInput(
35 `Do you really want to delete ${videoChannel.displayName}? It will delete all videos uploaded in this channel too.`,
36 'Please type the name of the video channel to confirm',
37 videoChannel.displayName,
40 if (res === false) return
42 this.videoChannelService.removeVideoChannel(videoChannel)
45 this.loadVideoChannels()
46 this.notificationsService.success('Success', `Video channel ${videoChannel.name} deleted.`)
49 error => this.notificationsService.error('Error', error.message)
53 private loadVideoChannels () {
54 this.authService.userInformationLoaded
55 .pipe(flatMap(() => this.videoChannelService.listAccountVideoChannels(this.user.account)))
56 .subscribe(res => this.videoChannels = res.data)