From 9556ce48e7d0aaed35753d982327bc60e1284894 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 25 Feb 2021 09:09:41 +0100 Subject: Fix async issues with channels list --- client/src/app/helpers/utils.ts | 44 +++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 26 deletions(-) (limited to 'client/src/app/helpers') 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 @@ +import { map } from 'rxjs/operators' import { SelectChannelItem } from 'src/types/select-options-item.model' import { DatePipe } from '@angular/common' import { HttpErrorResponse } from '@angular/common/http' @@ -20,31 +21,22 @@ function getParameterByName (name: string, url: string) { return decodeURIComponent(results[2].replace(/\+/g, ' ')) } -function populateAsyncUserVideoChannels ( - authService: AuthService, - channel: SelectChannelItem[] -) { - return new Promise(res => { - authService.userInformationLoaded - .subscribe( - () => { - const user = authService.getUser() - if (!user) return - - const videoChannels = user.videoChannels - if (Array.isArray(videoChannels) === false) return - - videoChannels.forEach(c => channel.push({ - id: c.id, - label: c.displayName, - support: c.support, - avatarPath: c.avatar?.path - })) - - return res() - } - ) - }) +function listUserChannels (authService: AuthService) { + return authService.userInformationLoaded + .pipe(map(() => { + const user = authService.getUser() + if (!user) return undefined + + const videoChannels = user.videoChannels + if (Array.isArray(videoChannels) === false) return undefined + + return videoChannels.map(c => ({ + id: c.id, + label: c.displayName, + support: c.support, + avatarPath: c.avatar?.path + }) as SelectChannelItem) + })) } function getAbsoluteAPIUrl () { @@ -207,7 +199,6 @@ export { durationToString, lineFeedToHtml, getParameterByName, - populateAsyncUserVideoChannels, getAbsoluteAPIUrl, dateToHuman, immutableAssign, @@ -218,5 +209,6 @@ export { scrollToTop, isInViewport, isXPercentInViewport, + listUserChannels, uploadErrorHandler } -- cgit v1.2.3