aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/helpers/utils.ts
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/src/app/helpers/utils.ts
parent9514bb3bc0534c2a8c5ffefac013a1b8d3717c0a (diff)
downloadPeerTube-9556ce48e7d0aaed35753d982327bc60e1284894.tar.gz
PeerTube-9556ce48e7d0aaed35753d982327bc60e1284894.tar.zst
PeerTube-9556ce48e7d0aaed35753d982327bc60e1284894.zip
Fix async issues with channels list
Diffstat (limited to 'client/src/app/helpers/utils.ts')
-rw-r--r--client/src/app/helpers/utils.ts44
1 files changed, 18 insertions, 26 deletions
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}