From 4d2e1c411fc936aa36384ec0a5e325f2f119b4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Fern=C3=A1ndez?= Date: Thu, 23 Feb 2023 19:10:59 +0100 Subject: [PATCH] chore: sonarcloud and unicorn fixes --- .../components/Layout/VirtualGrid/pipeline.ts | 16 ++--- frontend/src/pages/settings/devices.vue | 4 +- frontend/src/store/userLibraries.ts | 32 +++++----- frontend/src/utils/images.ts | 63 +++++++------------ 4 files changed, 47 insertions(+), 68 deletions(-) diff --git a/frontend/src/components/Layout/VirtualGrid/pipeline.ts b/frontend/src/components/Layout/VirtualGrid/pipeline.ts index b3c24a31ea5..51acdd8f65d 100644 --- a/frontend/src/components/Layout/VirtualGrid/pipeline.ts +++ b/frontend/src/components/Layout/VirtualGrid/pipeline.ts @@ -80,13 +80,15 @@ export function getScrollParents( while (parent && !vertical && !horizontal) { const parentStyle = getComputedStyle(parent); - if (!horizontal && overflowRegex.test(parentStyle.overflowX)) { - horizontal = parent; - } - - if (!vertical && overflowRegex.test(parentStyle.overflowY)) { - vertical = parent; - } + horizontal = + overflowRegex.test(parentStyle.overflowX) && !horizontal + ? parent + : undefined; + + vertical = + overflowRegex.test(parentStyle.overflowY) && !vertical + ? parent + : undefined; /** * parent.assignedSlot.parentElement find the correct parent if the grid is inside a native web component diff --git a/frontend/src/pages/settings/devices.vue b/frontend/src/pages/settings/devices.vue index ee6072fd577..b69ab2fd15f 100644 --- a/frontend/src/pages/settings/devices.vue +++ b/frontend/src/pages/settings/devices.vue @@ -118,7 +118,7 @@ export default defineComponent({ }, async deleteAllDevices(): Promise { try { - this.devices?.forEach(async (device) => { + for (const device of this.devices ?? []) { if (this.$remote.sdk.deviceInfo.id === device.Id) { return; } @@ -126,7 +126,7 @@ export default defineComponent({ await this.$remote.sdk .newUserApi(getDevicesApi) .deleteDevice({ id: device.Id || '' }); - }); + } this.useSnackbar( this.$t('settings.devices.deleteAllDevicesSuccess'), diff --git a/frontend/src/store/userLibraries.ts b/frontend/src/store/userLibraries.ts index adea739dec0..c216137dc34 100644 --- a/frontend/src/store/userLibraries.ts +++ b/frontend/src/store/userLibraries.ts @@ -104,12 +104,19 @@ class UserLibrariesStore { } }).value; }; + /** * == ACTIONS == */ + private _onError = (error: unknown): void => { + const { t } = usei18n(); + + console.error(error); + useSnackbar(t('errors.anErrorHappened'), 'error'); + }; + private _fetchUserViews = async (): Promise => { const remote = useRemote(); - const { t } = usei18n(); try { const userViewsResponse = await remote.sdk @@ -120,14 +127,12 @@ class UserLibrariesStore { state.value.views = userViewsResponse.data.Items || []; } catch (error) { - console.error(error); - useSnackbar(t('errors.anErrorHappened'), 'error'); + this._onError(error); } }; private _fetchAudioResumes = async (): Promise => { const remote = useRemote(); - const { t } = usei18n(); try { const audioResumes = ( @@ -150,14 +155,12 @@ class UserLibrariesStore { state.value.homeSections.audioResumes = audioResumes; } } catch (error) { - console.error(error); - useSnackbar(t('errors.anErrorHappened'), 'error'); + this._onError(error); } }; private _fetchVideoResumes = async (): Promise => { const remote = useRemote(); - const { t } = usei18n(); try { const videoResumes = ( @@ -180,14 +183,12 @@ class UserLibrariesStore { state.value.homeSections.videoResumes = videoResumes; } } catch (error) { - console.error(error); - useSnackbar(t('errors.anErrorHappened'), 'error'); + this._onError(error); } }; private _fetchUpNext = async (libraryId: string): Promise => { const remote = useRemote(); - const { t } = usei18n(); try { const upNext = ( @@ -209,14 +210,12 @@ class UserLibrariesStore { state.value.homeSections.upNext = upNext; } } catch (error) { - console.error(error); - useSnackbar(t('errors.anErrorHappened'), 'error'); + this._onError(error); } }; private _fetchLatestMedia = async (libraryId: string): Promise => { const remote = useRemote(); - const { t } = usei18n(); try { const latestMedia = ( @@ -236,14 +235,12 @@ class UserLibrariesStore { state.value.homeSections.latestMedia[libraryId] = latestMedia; } catch (error) { - console.error(error); - useSnackbar(t('errors.anErrorHappened'), 'error'); + this._onError(error); } }; private _fetchIndexCarouselItems = async (): Promise => { const remote = useRemote(); - const { t } = usei18n(); try { const carouselItems = ( @@ -260,8 +257,7 @@ class UserLibrariesStore { state.value.carouselItems = carouselItems; } } catch (error) { - console.error(error); - useSnackbar(t('errors.anErrorHappened'), 'error'); + this._onError(error); } }; diff --git a/frontend/src/utils/images.ts b/frontend/src/utils/images.ts index f181dab7feb..ef092a24cb0 100644 --- a/frontend/src/utils/images.ts +++ b/frontend/src/utils/images.ts @@ -4,6 +4,7 @@ */ import { BaseItemDto, + BaseItemKind, BaseItemPerson, ImageType } from '@jellyfin/sdk/lib/generated-client'; @@ -21,7 +22,9 @@ export interface ImageUrlInfo { blurhash: string | undefined; } -const excludedBlurhashTypes = new Set([ImageType.Logo]); +const excludedBlurhashTypes = Object.freeze( + new Set([ImageType.Logo]) +); /** * Gets the tag of the image of an specific item and type. @@ -38,10 +41,6 @@ export function getImageTag( index = 0, checkParent = true ): string | undefined { - if (!item) { - return; - } - if (isPerson(item)) { return item.PrimaryImageTag && type === ImageType.Primary ? item.PrimaryImageTag @@ -57,46 +56,24 @@ export function getImageTag( if (checkParent) { switch (type) { case ImageType.Primary: { - if (item.AlbumPrimaryImageTag) { - return item.AlbumPrimaryImageTag; - } else if (item.ChannelPrimaryImageTag) { - return item.ChannelPrimaryImageTag; - } else if (item.ParentPrimaryImageTag) { - return item.ParentPrimaryImageTag; - } - - break; + return ( + item.AlbumPrimaryImageTag || + item.ChannelPrimaryImageTag || + item.ParentPrimaryImageTag || + undefined + ); } case ImageType.Art: { - if (item.ParentArtImageTag) { - return item.ParentArtImageTag; - } - - break; + return item.ParentArtImageTag ?? undefined; } case ImageType.Backdrop: { - if (item.ParentBackdropImageTags?.[index]) { - return item.ParentBackdropImageTags[index]; - } - - break; + return item.ParentBackdropImageTags?.[index] ?? undefined; } case ImageType.Logo: { - if (item.ParentLogoImageTag) { - return item.ParentLogoImageTag; - } - - break; + return item.ParentLogoImageTag ?? undefined; } case ImageType.Thumb: { - if (item.ParentThumbImageTag) { - return item.ParentThumbImageTag; - } - - break; - } - default: { - return undefined; + return item.ParentThumbImageTag ?? undefined; } } } @@ -309,7 +286,7 @@ export function getImageInfo( item.ParentBackdropImageTags && item.ParentBackdropImageTags.length > 0 && inheritThumb && - item.Type === 'Episode' + item.Type === BaseItemKind.Episode ) { imgType = ImageType.Backdrop; imgTag = item.ParentBackdropImageTags[0]; @@ -317,7 +294,7 @@ export function getImageInfo( } else if ( item.ImageTags && item.ImageTags.Primary && - (item.Type !== 'Episode' || item.ChildCount !== 0) + (item.Type !== BaseItemKind.Episode || item.ChildCount !== 0) ) { imgType = ImageType.Primary; imgTag = item.ImageTags.Primary; @@ -341,7 +318,11 @@ export function getImageInfo( width && item.PrimaryImageAspectRatio ? Math.round(width / item.PrimaryImageAspectRatio) : undefined; - } else if (item.Type === 'Season' && item.ImageTags && item.ImageTags.Thumb) { + } else if ( + item.Type === BaseItemKind.Season && + item.ImageTags && + item.ImageTags.Thumb + ) { imgType = ImageType.Thumb; imgTag = item.ImageTags.Thumb; } else if (item.BackdropImageTags && item.BackdropImageTags.length > 0) { @@ -368,7 +349,7 @@ export function getImageInfo( itemId = item.ParentBackdropItemId; } - if (!itemId && !item.Id) { + if (!itemId && item.Id) { itemId = item.Id; }