]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-edit/video-add.component.ts
Add infinite scroll to comments
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-edit / video-add.component.ts
index 2bbc3de173f3857152795651e5e55eca0c842c75..9bbee58d8f2504f3be641349486f23646be30aea 100644 (file)
@@ -3,13 +3,13 @@ import { Component, OnInit, ViewChild } from '@angular/core'
 import { FormBuilder, FormGroup } from '@angular/forms'
 import { Router } from '@angular/router'
 import { NotificationsService } from 'angular2-notifications'
-import { VideoService } from 'app/shared/video/video.service'
-import { VideoCreate } from '../../../../../shared'
 import { VideoPrivacy } from '../../../../../shared/models/videos'
 import { AuthService, ServerService } from '../../core'
 import { FormReactive } from '../../shared'
-import { ValidatorMessage } from '../../shared/forms/form-validators'
+import { ValidatorMessage } from '../../shared/forms/form-validators/validator-message'
+import { populateAsyncUserVideoChannels } from '../../shared/misc/utils'
 import { VideoEdit } from '../../shared/video/video-edit.model'
+import { VideoService } from '../../shared/video/video.service'
 
 @Component({
   selector: 'my-videos-add',
@@ -26,7 +26,10 @@ export class VideoAddComponent extends FormReactive implements OnInit {
   isUploadingVideo = false
   videoUploaded = false
   videoUploadPercents = 0
-  videoUploadedId = 0
+  videoUploadedIds = {
+    id: 0,
+    uuid: ''
+  }
 
   error: string = null
   form: FormGroup
@@ -57,6 +60,9 @@ export class VideoAddComponent extends FormReactive implements OnInit {
   ngOnInit () {
     this.buildForm()
 
+    populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
+      .then(() => this.firstStepChannelId = this.userVideoChannels[0].id)
+
     this.serverService.videoPrivaciesLoaded
       .subscribe(
         () => {
@@ -65,20 +71,6 @@ export class VideoAddComponent extends FormReactive implements OnInit {
           // Public by default
           this.firstStepPrivacyId = VideoPrivacy.PUBLIC
         })
-
-    this.authService.userInformationLoaded
-      .subscribe(
-        () => {
-          const user = this.authService.getUser()
-          if (!user) return
-
-          const videoChannels = user.videoChannels
-          if (Array.isArray(videoChannels) === false) return
-
-          this.userVideoChannels = videoChannels.map(v => ({ id: v.id, label: v.name }))
-          this.firstStepChannelId = this.userVideoChannels[0].id
-        }
-      )
   }
 
   fileChange () {
@@ -123,7 +115,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
 
           this.videoUploaded = true
 
-          this.videoUploadedId = event.body.video.id
+          this.videoUploadedIds = event.body.video
         }
       },
 
@@ -143,13 +135,14 @@ export class VideoAddComponent extends FormReactive implements OnInit {
     const video = new VideoEdit()
     video.patch(this.form.value)
     video.channel = this.firstStepChannelId
-    video.id = this.videoUploadedId
+    video.id = this.videoUploadedIds.id
+    video.uuid = this.videoUploadedIds.uuid
 
     this.videoService.updateVideo(video)
       .subscribe(
         () => {
           this.notificationsService.success('Success', 'Video published.')
-          this.router.navigate([ '/videos/watch', video.id ])
+          this.router.navigate([ '/videos/watch', video.uuid ])
         },
 
         err => {