]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+videos/+video-edit/video-update.component.ts
Refactor video edition
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-update.component.ts
index 95336dc756add64437fad5e172a6c28470ab2f08..e44aea10ad978136c697c6d6170d8fedb582852e 100644 (file)
@@ -1,5 +1,5 @@
 import { of } from 'rxjs'
-import { map, switchMap } from 'rxjs/operators'
+import { switchMap } from 'rxjs/operators'
 import { SelectChannelItem } from 'src/types/select-options-item.model'
 import { Component, HostListener, OnInit } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
@@ -38,44 +38,35 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
     private loadingBar: LoadingBarService,
     private videoCaptionService: VideoCaptionService,
     private liveVideoService: LiveVideoService
-    ) {
+  ) {
     super()
   }
 
   ngOnInit () {
     this.buildForm({})
 
-    this.route.data
-        .pipe(map(data => data.videoData))
-        .subscribe({
-          next: ({ video, videoChannels, videoCaptions, liveVideo }) => {
-            this.video = new VideoEdit(video)
-            this.videoDetails = video
-
-            this.userVideoChannels = videoChannels
-            this.videoCaptions = videoCaptions
-            this.liveVideo = liveVideo
-
-            this.schedulePublicationPossible = this.video.privacy === VideoPrivacy.PRIVATE
-
-            // FIXME: Angular does not detect the change inside this subscription, so use the patched setTimeout
-            setTimeout(() => {
-              hydrateFormFromVideo(this.form, this.video, true)
-
-              if (this.liveVideo) {
-                this.form.patchValue({
-                  saveReplay: this.liveVideo.saveReplay,
-                  permanentLive: this.liveVideo.permanentLive
-                })
-              }
-            })
-          },
+    const { videoData } = this.route.snapshot.data
+    const { video, videoChannels, videoCaptions, liveVideo } = videoData
 
-          error: err => {
-            console.error(err)
-            this.notifier.error(err.message)
-          }
-        })
+    this.video = new VideoEdit(video)
+    this.videoDetails = video
+
+    this.userVideoChannels = videoChannels
+    this.videoCaptions = videoCaptions
+    this.liveVideo = liveVideo
+
+    this.schedulePublicationPossible = this.video.privacy === VideoPrivacy.PRIVATE
+  }
+
+  onFormBuilt () {
+    hydrateFormFromVideo(this.form, this.video, true)
+
+    if (this.liveVideo) {
+      this.form.patchValue({
+        saveReplay: this.liveVideo.saveReplay,
+        permanentLive: this.liveVideo.permanentLive
+      })
+    }
   }
 
   @HostListener('window:beforeunload', [ '$event' ])
@@ -119,8 +110,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
   }
 
   update () {
-    if (this.checkForm() === false
-      || this.isUpdatingVideo === true) {
+    if (this.checkForm() === false || this.isUpdatingVideo === true) {
       return
     }