aboutsummaryrefslogtreecommitdiffhomepage
path: root/client
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-25 09:09:41 +0100
committerChocobozzz <me@florianbigard.com>2021-02-25 09:09:41 +0100
commit9556ce48e7d0aaed35753d982327bc60e1284894 (patch)
tree89509d43b0e8c11c4cc5dcfa4de275ba29a92500 /client
parent9514bb3bc0534c2a8c5ffefac013a1b8d3717c0a (diff)
downloadPeerTube-9556ce48e7d0aaed35753d982327bc60e1284894.tar.gz
PeerTube-9556ce48e7d0aaed35753d982327bc60e1284894.tar.zst
PeerTube-9556ce48e7d0aaed35753d982327bc60e1284894.zip
Fix async issues with channels list
Diffstat (limited to 'client')
-rw-r--r--client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts6
-rw-r--r--client/src/app/+my-library/my-video-playlists/my-video-playlist-update.component.ts6
-rw-r--r--client/src/app/+videos/+video-edit/video-add-components/video-send.ts9
-rw-r--r--client/src/app/helpers/utils.ts44
4 files changed, 30 insertions, 35 deletions
diff --git a/client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts b/client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts
index 5abea54b0..8606a875a 100644
--- a/client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts
+++ b/client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts
@@ -1,7 +1,7 @@
1import { Component, OnInit } from '@angular/core' 1import { Component, OnInit } from '@angular/core'
2import { Router } from '@angular/router' 2import { Router } from '@angular/router'
3import { AuthService, Notifier, ServerService } from '@app/core' 3import { AuthService, Notifier, ServerService } from '@app/core'
4import { populateAsyncUserVideoChannels } from '@app/helpers' 4import { listUserChannels } from '@app/helpers'
5import { 5import {
6 setPlaylistChannelValidator, 6 setPlaylistChannelValidator,
7 VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR, 7 VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR,
@@ -46,8 +46,8 @@ export class MyVideoPlaylistCreateComponent extends MyVideoPlaylistEdit implemen
46 setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy) 46 setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy)
47 }) 47 })
48 48
49 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) 49 listUserChannels(this.authService)
50 .catch(err => console.error('Cannot populate user video channels.', err)) 50 .subscribe(channels => this.userVideoChannels = channels)
51 51
52 this.serverService.getVideoPlaylistPrivacies() 52 this.serverService.getVideoPlaylistPrivacies()
53 .subscribe(videoPlaylistPrivacies => { 53 .subscribe(videoPlaylistPrivacies => {
diff --git a/client/src/app/+my-library/my-video-playlists/my-video-playlist-update.component.ts b/client/src/app/+my-library/my-video-playlists/my-video-playlist-update.component.ts
index 532423ba2..c554d3772 100644
--- a/client/src/app/+my-library/my-video-playlists/my-video-playlist-update.component.ts
+++ b/client/src/app/+my-library/my-video-playlists/my-video-playlist-update.component.ts
@@ -3,7 +3,7 @@ import { map, switchMap } from 'rxjs/operators'
3import { Component, OnDestroy, OnInit } from '@angular/core' 3import { Component, OnDestroy, OnInit } from '@angular/core'
4import { ActivatedRoute, Router } from '@angular/router' 4import { ActivatedRoute, Router } from '@angular/router'
5import { AuthService, Notifier, ServerService } from '@app/core' 5import { AuthService, Notifier, ServerService } from '@app/core'
6import { populateAsyncUserVideoChannels } from '@app/helpers' 6import { listUserChannels } from '@app/helpers'
7import { 7import {
8 setPlaylistChannelValidator, 8 setPlaylistChannelValidator,
9 VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR, 9 VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR,
@@ -51,8 +51,8 @@ export class MyVideoPlaylistUpdateComponent extends MyVideoPlaylistEdit implemen
51 setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy) 51 setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy)
52 }) 52 })
53 53
54 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) 54 listUserChannels(this.authService)
55 .catch(err => console.error('Cannot populate user video channels.', err)) 55 .subscribe(channels => this.userVideoChannels = channels)
56 56
57 this.paramsSub = this.route.params 57 this.paramsSub = this.route.params
58 .pipe( 58 .pipe(
diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-send.ts b/client/src/app/+videos/+video-edit/video-add-components/video-send.ts
index 9a22024e5..3614499cd 100644
--- a/client/src/app/+videos/+video-edit/video-add-components/video-send.ts
+++ b/client/src/app/+videos/+video-edit/video-add-components/video-send.ts
@@ -2,7 +2,7 @@ import { catchError, switchMap, tap } from 'rxjs/operators'
2import { SelectChannelItem } from 'src/types/select-options-item.model' 2import { SelectChannelItem } from 'src/types/select-options-item.model'
3import { Directive, EventEmitter, OnInit } from '@angular/core' 3import { Directive, EventEmitter, OnInit } from '@angular/core'
4import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core' 4import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core'
5import { populateAsyncUserVideoChannels } from '@app/helpers' 5import { listUserChannels } from '@app/helpers'
6import { FormReactive } from '@app/shared/shared-forms' 6import { FormReactive } from '@app/shared/shared-forms'
7import { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main' 7import { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
8import { LoadingBarService } from '@ngx-loading-bar/core' 8import { LoadingBarService } from '@ngx-loading-bar/core'
@@ -35,8 +35,11 @@ export abstract class VideoSend extends FormReactive implements OnInit {
35 ngOnInit () { 35 ngOnInit () {
36 this.buildForm({}) 36 this.buildForm({})
37 37
38 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) 38 listUserChannels(this.authService)
39 .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id) 39 .subscribe(channels => {
40 this.userVideoChannels = channels
41 this.firstStepChannelId = this.userVideoChannels[0].id
42 })
40 43
41 this.serverConfig = this.serverService.getTmpConfig() 44 this.serverConfig = this.serverService.getTmpConfig()
42 this.serverService.getConfig() 45 this.serverService.getConfig()
diff --git a/client/src/app/helpers/utils.ts b/client/src/app/helpers/utils.ts
index 6d7e76b11..a1747af3c 100644
--- a/client/src/app/helpers/utils.ts
+++ b/client/src/app/helpers/utils.ts
@@ -1,3 +1,4 @@
1import { map } from 'rxjs/operators'
1import { SelectChannelItem } from 'src/types/select-options-item.model' 2import { SelectChannelItem } from 'src/types/select-options-item.model'
2import { DatePipe } from '@angular/common' 3import { DatePipe } from '@angular/common'
3import { HttpErrorResponse } from '@angular/common/http' 4import { HttpErrorResponse } from '@angular/common/http'
@@ -20,31 +21,22 @@ function getParameterByName (name: string, url: string) {
20 return decodeURIComponent(results[2].replace(/\+/g, ' ')) 21 return decodeURIComponent(results[2].replace(/\+/g, ' '))
21} 22}
22 23
23function populateAsyncUserVideoChannels ( 24function listUserChannels (authService: AuthService) {
24 authService: AuthService, 25 return authService.userInformationLoaded
25 channel: SelectChannelItem[] 26 .pipe(map(() => {
26) { 27 const user = authService.getUser()
27 return new Promise<void>(res => { 28 if (!user) return undefined
28 authService.userInformationLoaded 29
29 .subscribe( 30 const videoChannels = user.videoChannels
30 () => { 31 if (Array.isArray(videoChannels) === false) return undefined
31 const user = authService.getUser() 32
32 if (!user) return 33 return videoChannels.map(c => ({
33 34 id: c.id,
34 const videoChannels = user.videoChannels 35 label: c.displayName,
35 if (Array.isArray(videoChannels) === false) return 36 support: c.support,
36 37 avatarPath: c.avatar?.path
37 videoChannels.forEach(c => channel.push({ 38 }) as SelectChannelItem)
38 id: c.id, 39 }))
39 label: c.displayName,
40 support: c.support,
41 avatarPath: c.avatar?.path
42 }))
43
44 return res()
45 }
46 )
47 })
48} 40}
49 41
50function getAbsoluteAPIUrl () { 42function getAbsoluteAPIUrl () {
@@ -207,7 +199,6 @@ export {
207 durationToString, 199 durationToString,
208 lineFeedToHtml, 200 lineFeedToHtml,
209 getParameterByName, 201 getParameterByName,
210 populateAsyncUserVideoChannels,
211 getAbsoluteAPIUrl, 202 getAbsoluteAPIUrl,
212 dateToHuman, 203 dateToHuman,
213 immutableAssign, 204 immutableAssign,
@@ -218,5 +209,6 @@ export {
218 scrollToTop, 209 scrollToTop,
219 isInViewport, 210 isInViewport,
220 isXPercentInViewport, 211 isXPercentInViewport,
212 listUserChannels,
221 uploadErrorHandler 213 uploadErrorHandler
222} 214}