]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/video-caption/video-caption.service.ts
Sort video captions
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video-caption / video-caption.service.ts
index d1444902d1dd6e5dfe1a3c0d4149fbb62f38212b..0ff094d1fe0cc61ff960d0d4d42eb0243498a533 100644 (file)
@@ -6,7 +6,7 @@ import { ResultList } from '../../../../../shared'
 import { RestExtractor, RestService } from '../rest'
 import { VideoCaption } from '../../../../../shared/models/videos/video-caption.model'
 import { VideoService } from '@app/shared/video/video.service'
-import { objectToFormData } from '@app/shared/misc/utils'
+import { objectToFormData, sortBy } from '@app/shared/misc/utils'
 import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
 
 @Injectable()
@@ -19,6 +19,11 @@ export class VideoCaptionService {
 
   listCaptions (videoId: number | string): Observable<ResultList<VideoCaption>> {
     return this.authHttp.get<ResultList<VideoCaption>>(VideoService.BASE_VIDEO_URL + videoId + '/captions')
+               .pipe(map(res => {
+                 sortBy(res.data, 'language', 'label')
+
+                 return res
+               }))
                .pipe(catchError(res => this.restExtractor.handleError(res)))
   }
 
@@ -42,8 +47,6 @@ export class VideoCaptionService {
   }
 
   updateCaptions (videoId: number | string, videoCaptions: VideoCaptionEdit[]) {
-    if (videoCaptions.length === 0) return of(true)
-
     const observables: Observable<any>[] = []
 
     for (const videoCaption of videoCaptions) {
@@ -58,6 +61,8 @@ export class VideoCaptionService {
       }
     }
 
+    if (observables.length === 0) return of(true)
+
     return forkJoin(observables)
   }
 }