diff options
Diffstat (limited to 'client/src/app/helpers')
-rw-r--r-- | client/src/app/helpers/utils/channel.ts | 16 | ||||
-rw-r--r-- | client/src/app/helpers/utils/dom.ts (renamed from client/src/app/helpers/utils/ui.ts) | 26 | ||||
-rw-r--r-- | client/src/app/helpers/utils/index.ts | 2 | ||||
-rw-r--r-- | client/src/app/helpers/utils/url.ts | 5 |
4 files changed, 37 insertions, 12 deletions
diff --git a/client/src/app/helpers/utils/channel.ts b/client/src/app/helpers/utils/channel.ts index 93863a8af..83f36b70f 100644 --- a/client/src/app/helpers/utils/channel.ts +++ b/client/src/app/helpers/utils/channel.ts | |||
@@ -1,8 +1,10 @@ | |||
1 | import { minBy } from 'lodash-es' | ||
1 | import { first, map } from 'rxjs/operators' | 2 | import { first, map } from 'rxjs/operators' |
2 | import { SelectChannelItem } from 'src/types/select-options-item.model' | 3 | import { SelectChannelItem } from 'src/types/select-options-item.model' |
4 | import { VideoChannel } from '@shared/models' | ||
3 | import { AuthService } from '../../core/auth' | 5 | import { AuthService } from '../../core/auth' |
4 | 6 | ||
5 | function listUserChannels (authService: AuthService) { | 7 | function listUserChannelsForSelect (authService: AuthService) { |
6 | return authService.userInformationLoaded | 8 | return authService.userInformationLoaded |
7 | .pipe( | 9 | .pipe( |
8 | first(), | 10 | first(), |
@@ -23,12 +25,20 @@ function listUserChannels (authService: AuthService) { | |||
23 | id: c.id, | 25 | id: c.id, |
24 | label: c.displayName, | 26 | label: c.displayName, |
25 | support: c.support, | 27 | support: c.support, |
26 | avatarPath: c.avatar?.path | 28 | avatarPath: getAvatarPath(c) |
27 | }) as SelectChannelItem) | 29 | }) as SelectChannelItem) |
28 | }) | 30 | }) |
29 | ) | 31 | ) |
30 | } | 32 | } |
31 | 33 | ||
32 | export { | 34 | export { |
33 | listUserChannels | 35 | listUserChannelsForSelect |
36 | } | ||
37 | |||
38 | // --------------------------------------------------------------------------- | ||
39 | |||
40 | function getAvatarPath (c: VideoChannel) { | ||
41 | if (!c.avatars || c.avatars.length === 0) return undefined | ||
42 | |||
43 | return minBy(c.avatars, 'width').path | ||
34 | } | 44 | } |
diff --git a/client/src/app/helpers/utils/ui.ts b/client/src/app/helpers/utils/dom.ts index ac8298926..f65e4d726 100644 --- a/client/src/app/helpers/utils/ui.ts +++ b/client/src/app/helpers/utils/dom.ts | |||
@@ -6,14 +6,24 @@ function scrollToTop (behavior: 'auto' | 'smooth' = 'auto') { | |||
6 | }) | 6 | }) |
7 | } | 7 | } |
8 | 8 | ||
9 | function isInViewport (el: HTMLElement) { | 9 | function isInViewport (el: HTMLElement, container: HTMLElement = document.documentElement) { |
10 | const bounding = el.getBoundingClientRect() | 10 | const boundingEl = el.getBoundingClientRect() |
11 | return ( | 11 | const boundingContainer = container.getBoundingClientRect() |
12 | bounding.top >= 0 && | 12 | |
13 | bounding.left >= 0 && | 13 | const relativePos = { |
14 | bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) && | 14 | top: 0, |
15 | bounding.right <= (window.innerWidth || document.documentElement.clientWidth) | 15 | left: 0, |
16 | ) | 16 | bottom: 0, |
17 | right: 0 | ||
18 | } | ||
19 | |||
20 | relativePos.top = boundingEl.top - boundingContainer.top | ||
21 | relativePos.left = boundingEl.left - boundingContainer.left | ||
22 | |||
23 | return relativePos.top >= 0 && | ||
24 | relativePos.left >= 0 && | ||
25 | boundingEl.bottom <= boundingContainer.bottom && | ||
26 | boundingEl.right <= boundingContainer.right | ||
17 | } | 27 | } |
18 | 28 | ||
19 | function isXPercentInViewport (el: HTMLElement, percentVisible: number) { | 29 | function isXPercentInViewport (el: HTMLElement, percentVisible: number) { |
diff --git a/client/src/app/helpers/utils/index.ts b/client/src/app/helpers/utils/index.ts index dc09c92ab..f821985c9 100644 --- a/client/src/app/helpers/utils/index.ts +++ b/client/src/app/helpers/utils/index.ts | |||
@@ -2,6 +2,6 @@ export * from './channel' | |||
2 | export * from './date' | 2 | export * from './date' |
3 | export * from './html' | 3 | export * from './html' |
4 | export * from './object' | 4 | export * from './object' |
5 | export * from './ui' | 5 | export * from './dom' |
6 | export * from './upload' | 6 | export * from './upload' |
7 | export * from './url' | 7 | export * from './url' |
diff --git a/client/src/app/helpers/utils/url.ts b/client/src/app/helpers/utils/url.ts index b3cded8f4..08c27e3c1 100644 --- a/client/src/app/helpers/utils/url.ts +++ b/client/src/app/helpers/utils/url.ts | |||
@@ -13,6 +13,10 @@ function getAbsoluteAPIUrl () { | |||
13 | return absoluteAPIUrl | 13 | return absoluteAPIUrl |
14 | } | 14 | } |
15 | 15 | ||
16 | function getAPIHost () { | ||
17 | return new URL(getAbsoluteAPIUrl()).host | ||
18 | } | ||
19 | |||
16 | function getAbsoluteEmbedUrl () { | 20 | function getAbsoluteEmbedUrl () { |
17 | let absoluteEmbedUrl = environment.originServerUrl | 21 | let absoluteEmbedUrl = environment.originServerUrl |
18 | if (!absoluteEmbedUrl) { | 22 | if (!absoluteEmbedUrl) { |
@@ -52,5 +56,6 @@ function objectToFormData (obj: any, form?: FormData, namespace?: string) { | |||
52 | export { | 56 | export { |
53 | objectToFormData, | 57 | objectToFormData, |
54 | getAbsoluteAPIUrl, | 58 | getAbsoluteAPIUrl, |
59 | getAPIHost, | ||
55 | getAbsoluteEmbedUrl | 60 | getAbsoluteEmbedUrl |
56 | } | 61 | } |