Fix video support field update
authorChocobozzz <me@florianbigard.com>
Fri, 27 Dec 2019 13:41:41 +0000 (14:41 +0100)
committerChocobozzz <me@florianbigard.com>
Fri, 27 Dec 2019 13:41:50 +0000 (14:41 +0100)
client/src/app/videos/+video-edit/shared/video-edit.component.ts

index 982e071ad535a5bd2bb21ef0c8fb3ab438a08f80..15073fc44dc4cbf71d61bc887aba44cefd30fda8 100644 (file)
@@ -248,28 +248,32 @@ export class VideoEditComponent implements OnInit, OnDestroy {
       .subscribe(
         newChannelId => {
           const oldChannelId = parseInt(this.form.value[ 'channelId' ], 10)
-          const currentSupport = this.form.value[ 'support' ]
 
           // Not initialized yet
           if (isNaN(newChannelId)) return
           const newChannel = this.userVideoChannels.find(c => c.id === newChannelId)
           if (!newChannel) return
 
-          // First time we set the channel?
-          if (isNaN(oldChannelId)) return this.updateSupportField(newChannel.support)
-          const oldChannel = this.userVideoChannels.find(c => c.id === oldChannelId)
+          // Wait support field update
+          setTimeout(() => {
+            const currentSupport = this.form.value[ 'support' ]
 
-          if (!newChannel || !oldChannel) {
-            console.error('Cannot find new or old channel.')
-            return
-          }
+            // First time we set the channel?
+            if (isNaN(oldChannelId) && !currentSupport) return this.updateSupportField(newChannel.support)
+
+            const oldChannel = this.userVideoChannels.find(c => c.id === oldChannelId)
+            if (!newChannel || !oldChannel) {
+              console.error('Cannot find new or old channel.')
+              return
+            }
 
-          // If the current support text is not the same than the old channel, the user updated it.
-          // We don't want the user to lose his text, so stop here
-          if (currentSupport && currentSupport !== oldChannel.support) return
+            // If the current support text is not the same than the old channel, the user updated it.
+            // We don't want the user to lose his text, so stop here
+            if (currentSupport && currentSupport !== oldChannel.support) return
 
-          // Update the support text with our new channel
-          this.updateSupportField(newChannel.support)
+            // Update the support text with our new channel
+            this.updateSupportField(newChannel.support)
+          })
         }
       )
   }