]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts
Refactor form reactive
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add-components / video-import-torrent.component.ts
index c369ba2b7a156efc81ab8602477dc9b89585834e..4a1408a4af30c1c60f29c80c04f8ede44a3f520a 100644 (file)
@@ -1,10 +1,12 @@
+import { switchMap } from 'rxjs'
 import { AfterViewInit, Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
 import { Router } from '@angular/router'
 import { AuthService, CanComponentDeactivate, HooksService, Notifier, ServerService } from '@app/core'
 import { scrollToTop } from '@app/helpers'
-import { FormValidatorService } from '@app/shared/shared-forms'
+import { FormReactiveService } from '@app/shared/shared-forms'
 import { VideoCaptionService, VideoEdit, VideoImportService, VideoService } from '@app/shared/shared-main'
 import { LoadingBarService } from '@ngx-loading-bar/core'
+import { logger } from '@root-helpers/logger'
 import { PeerTubeProblemDocument, ServerErrorCode, VideoUpdate } from '@shared/models'
 import { hydrateFormFromVideo } from '../shared/video-edit-utils'
 import { VideoSend } from './video-send'
@@ -33,7 +35,7 @@ export class VideoImportTorrentComponent extends VideoSend implements OnInit, Af
   error: string
 
   constructor (
-    protected formValidatorService: FormValidatorService,
+    protected formReactiveService: FormReactiveService,
     protected loadingBar: LoadingBarService,
     protected notifier: Notifier,
     protected authService: AuthService,
@@ -87,21 +89,16 @@ export class VideoImportTorrentComponent extends VideoSend implements OnInit, Af
     this.loadingBar.useRef().start()
 
     this.videoImportService.importVideoTorrent(torrentfile || this.magnetUri, videoUpdate)
+      .pipe(switchMap(({ video }) => this.videoService.getVideo({ videoId: video.uuid })))
       .subscribe({
-        next: res => {
+        next: video => {
           this.loadingBar.useRef().complete()
-          this.firstStepDone.emit(res.video.name)
+          this.firstStepDone.emit(video.name)
           this.isImportingVideo = false
           this.hasImportedVideo = true
 
-          this.video = new VideoEdit(Object.assign(res.video, {
-            commentsEnabled: videoUpdate.commentsEnabled,
-            downloadEnabled: videoUpdate.downloadEnabled,
-            privacy: { id: this.firstStepPrivacyId },
-            support: null,
-            thumbnailUrl: null,
-            previewUrl: null
-          }))
+          this.video = new VideoEdit(video)
+          this.video.patch({ privacy: this.firstStepPrivacyId })
 
           hydrateFormFromVideo(this.form, this.video, false)
         },
@@ -143,7 +140,7 @@ export class VideoImportTorrentComponent extends VideoSend implements OnInit, Af
           error: err => {
             this.error = err.message
             scrollToTop()
-            console.error(err)
+            logger.error(err)
           }
         })
   }