]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-edit/shared/video-edit.component.ts
Sort video captions
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-edit / shared / video-edit.component.ts
index b8aef99ddb94ef2c9ea5c558fb9540c25096fa1d..b394a13e4932c5fa8125dde7c13e72a826fcbe4f 100644 (file)
@@ -142,12 +142,13 @@ export class VideoEditComponent implements OnInit, OnDestroy {
     // Replace existing caption?
     if (existingCaption) {
       Object.assign(existingCaption, caption, { action: 'CREATE' as 'CREATE' })
-      return
+    } else {
+      this.videoCaptions.push(
+        Object.assign(caption, { action: 'CREATE' as 'CREATE' })
+      )
     }
 
-    this.videoCaptions.push(
-      Object.assign(caption, { action: 'CREATE' as 'CREATE' })
-    )
+    this.sortVideoCaptions()
   }
 
   async deleteCaption (caption: VideoCaptionEdit) {
@@ -170,6 +171,15 @@ export class VideoEditComponent implements OnInit, OnDestroy {
     this.videoCaptionAddModal.show()
   }
 
+  private sortVideoCaptions () {
+    this.videoCaptions.sort((v1, v2) => {
+      if (v1.language.label < v2.language.label) return -1
+      if (v1.language.label === v2.language.label) return 0
+
+      return 1
+    })
+  }
+
   private trackPrivacyChange () {
     // We will update the "support" field depending on the channel
     this.form.controls[ 'privacy' ]