Skip to content

Commit

Permalink
chore: sonarcloud and unicorn fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ferferga committed Feb 23, 2023
1 parent 3884c5d commit 4d2e1c4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 68 deletions.
16 changes: 9 additions & 7 deletions frontend/src/components/Layout/VirtualGrid/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/settings/devices.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ export default defineComponent({
},
async deleteAllDevices(): Promise<void> {
try {
this.devices?.forEach(async (device) => {
for (const device of this.devices ?? []) {
if (this.$remote.sdk.deviceInfo.id === device.Id) {
return;
}
await this.$remote.sdk
.newUserApi(getDevicesApi)
.deleteDevice({ id: device.Id || '' });
});
}
this.useSnackbar(
this.$t('settings.devices.deleteAllDevicesSuccess'),
Expand Down
32 changes: 14 additions & 18 deletions frontend/src/store/userLibraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
const remote = useRemote();
const { t } = usei18n();

try {
const userViewsResponse = await remote.sdk
Expand All @@ -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<void> => {
const remote = useRemote();
const { t } = usei18n();

try {
const audioResumes = (
Expand All @@ -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<void> => {
const remote = useRemote();
const { t } = usei18n();

try {
const videoResumes = (
Expand All @@ -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<void> => {
const remote = useRemote();
const { t } = usei18n();

try {
const upNext = (
Expand All @@ -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<void> => {
const remote = useRemote();
const { t } = usei18n();

try {
const latestMedia = (
Expand All @@ -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<void> => {
const remote = useRemote();
const { t } = usei18n();

try {
const carouselItems = (
Expand All @@ -260,8 +257,7 @@ class UserLibrariesStore {
state.value.carouselItems = carouselItems;
}
} catch (error) {
console.error(error);
useSnackbar(t('errors.anErrorHappened'), 'error');
this._onError(error);
}
};

Expand Down
63 changes: 22 additions & 41 deletions frontend/src/utils/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
import {
BaseItemDto,
BaseItemKind,
BaseItemPerson,
ImageType
} from '@jellyfin/sdk/lib/generated-client';
Expand All @@ -21,7 +22,9 @@ export interface ImageUrlInfo {
blurhash: string | undefined;
}

const excludedBlurhashTypes = new Set([ImageType.Logo]);
const excludedBlurhashTypes = Object.freeze(
new Set<ImageType>([ImageType.Logo])
);

/**
* Gets the tag of the image of an specific item and type.
Expand All @@ -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
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -309,15 +286,15 @@ export function getImageInfo(
item.ParentBackdropImageTags &&
item.ParentBackdropImageTags.length > 0 &&
inheritThumb &&
item.Type === 'Episode'
item.Type === BaseItemKind.Episode
) {
imgType = ImageType.Backdrop;
imgTag = item.ParentBackdropImageTags[0];
itemId = item.ParentBackdropItemId;
} 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;
Expand All @@ -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) {
Expand All @@ -368,7 +349,7 @@ export function getImageInfo(
itemId = item.ParentBackdropItemId;
}

if (!itemId && !item.Id) {
if (!itemId && item.Id) {
itemId = item.Id;
}

Expand Down

0 comments on commit 4d2e1c4

Please sign in to comment.