aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/helpers')
-rw-r--r--client/src/app/helpers/utils.ts48
1 files changed, 30 insertions, 18 deletions
diff --git a/client/src/app/helpers/utils.ts b/client/src/app/helpers/utils.ts
index a1747af3c..94f6def26 100644
--- a/client/src/app/helpers/utils.ts
+++ b/client/src/app/helpers/utils.ts
@@ -1,4 +1,4 @@
1import { map } from 'rxjs/operators' 1import { first, map } from 'rxjs/operators'
2import { SelectChannelItem } from 'src/types/select-options-item.model' 2import { SelectChannelItem } from 'src/types/select-options-item.model'
3import { DatePipe } from '@angular/common' 3import { DatePipe } from '@angular/common'
4import { HttpErrorResponse } from '@angular/common/http' 4import { HttpErrorResponse } from '@angular/common/http'
@@ -23,20 +23,29 @@ function getParameterByName (name: string, url: string) {
23 23
24function listUserChannels (authService: AuthService) { 24function listUserChannels (authService: AuthService) {
25 return authService.userInformationLoaded 25 return authService.userInformationLoaded
26 .pipe(map(() => { 26 .pipe(
27 const user = authService.getUser() 27 first(),
28 if (!user) return undefined 28 map(() => {
29 29 const user = authService.getUser()
30 const videoChannels = user.videoChannels 30 if (!user) return undefined
31 if (Array.isArray(videoChannels) === false) return undefined 31
32 32 const videoChannels = user.videoChannels
33 return videoChannels.map(c => ({ 33 if (Array.isArray(videoChannels) === false) return undefined
34 id: c.id, 34
35 label: c.displayName, 35 return videoChannels
36 support: c.support, 36 .sort((a, b) => {
37 avatarPath: c.avatar?.path 37 if (a.updatedAt < b.updatedAt) return 1
38 }) as SelectChannelItem) 38 if (a.updatedAt > b.updatedAt) return -1
39 })) 39 return 0
40 })
41 .map(c => ({
42 id: c.id,
43 label: c.displayName,
44 support: c.support,
45 avatarPath: c.avatar?.path
46 }) as SelectChannelItem)
47 })
48 )
40} 49}
41 50
42function getAbsoluteAPIUrl () { 51function getAbsoluteAPIUrl () {
@@ -167,8 +176,8 @@ function isXPercentInViewport (el: HTMLElement, percentVisible: number) {
167 ) 176 )
168} 177}
169 178
170function uploadErrorHandler (parameters: { 179function genericUploadErrorHandler (parameters: {
171 err: HttpErrorResponse 180 err: Pick<HttpErrorResponse, 'message' | 'status' | 'headers'>
172 name: string 181 name: string
173 notifier: Notifier 182 notifier: Notifier
174 sticky?: boolean 183 sticky?: boolean
@@ -180,6 +189,9 @@ function uploadErrorHandler (parameters: {
180 if (err instanceof ErrorEvent) { // network error 189 if (err instanceof ErrorEvent) { // network error
181 message = $localize`The connection was interrupted` 190 message = $localize`The connection was interrupted`
182 notifier.error(message, title, null, sticky) 191 notifier.error(message, title, null, sticky)
192 } else if (err.status === HttpStatusCode.INTERNAL_SERVER_ERROR_500) {
193 message = $localize`The server encountered an error`
194 notifier.error(message, title, null, sticky)
183 } else if (err.status === HttpStatusCode.REQUEST_TIMEOUT_408) { 195 } else if (err.status === HttpStatusCode.REQUEST_TIMEOUT_408) {
184 message = $localize`Your ${name} file couldn't be transferred before the set timeout (usually 10min)` 196 message = $localize`Your ${name} file couldn't be transferred before the set timeout (usually 10min)`
185 notifier.error(message, title, null, sticky) 197 notifier.error(message, title, null, sticky)
@@ -210,5 +222,5 @@ export {
210 isInViewport, 222 isInViewport,
211 isXPercentInViewport, 223 isXPercentInViewport,
212 listUserChannels, 224 listUserChannels,
213 uploadErrorHandler 225 genericUploadErrorHandler
214} 226}