]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Cleanup video update component
authorChocobozzz <me@florianbigard.com>
Fri, 22 Oct 2021 13:51:02 +0000 (15:51 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 22 Oct 2021 13:51:02 +0000 (15:51 +0200)
client/src/app/+videos/+video-edit/shared/video-edit.component.ts
client/src/app/+videos/+video-edit/video-update.component.html
client/src/app/+videos/+video-edit/video-update.component.ts

index bf7fdeeed438971777ad4c1387106732e2916889..b4638c2df1225968c9c5c04a7438cfc99aee7c71 100644 (file)
@@ -63,6 +63,7 @@ export class VideoEditComponent implements OnInit, OnDestroy {
 
   @ViewChild('videoCaptionAddModal', { static: true }) videoCaptionAddModal: VideoCaptionAddModalComponent
 
+  @Output() formBuilt = new EventEmitter<void>()
   @Output() pluginFieldsAdded = new EventEmitter<void>()
 
   // So that it can be accessed in the template
@@ -154,6 +155,8 @@ export class VideoEditComponent implements OnInit, OnDestroy {
     this.trackChannelChange()
     this.trackPrivacyChange()
     this.trackLivePermanentFieldChange()
+
+    this.formBuilt.emit()
   }
 
   ngOnInit () {
index 33e3ddd143862f1aac65b72d0aed9d19c7977a15..ca322318c68ac116042c224114a05b7700424f76 100644 (file)
@@ -12,6 +12,8 @@
       [videoCaptions]="videoCaptions" [waitTranscodingEnabled]="isWaitTranscodingEnabled()"
       type="update" (pluginFieldsAdded)="hydratePluginFieldsFromVideo()"
       [liveVideo]="liveVideo" [videoToUpdate]="videoDetails"
+
+      (formBuilt)="onFormBuilt()"
     ></my-video-edit>
 
     <div class="submit-container">
index 9bef60133d7c853a9c3b2d3176bdf30e3d8073f9..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'
@@ -45,37 +45,28 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
   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' ])