1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Replace existence check with optional chaining (#5742)

This commit is contained in:
Peter Santos 2024-08-17 02:58:01 -04:00 committed by GitHub
parent cc22fbc042
commit 1da9b548ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 21 additions and 21 deletions

View file

@ -178,7 +178,7 @@ function getItemImageUrls(item, imageOptions) {
});
}
if (item.ParentBackdropItemId && item.ParentBackdropImageTags && item.ParentBackdropImageTags.length) {
if (item.ParentBackdropItemId && item.ParentBackdropImageTags?.length) {
return item.ParentBackdropImageTags.map((imgTag, index) => {
return apiClient.getScaledImageUrl(item.ParentBackdropItemId, Object.assign(imageOptions, {
type: 'Backdrop',

View file

@ -277,16 +277,16 @@ export function getCardImageUrl(item, apiClient, options, shape) {
let itemId = null;
/* eslint-disable sonarjs/no-duplicated-branches */
if (options.preferThumb && item.ImageTags && item.ImageTags.Thumb) {
if (options.preferThumb && item.ImageTags?.Thumb) {
imgType = 'Thumb';
imgTag = item.ImageTags.Thumb;
} else if ((options.preferBanner || shape === 'banner') && item.ImageTags && item.ImageTags.Banner) {
} else if ((options.preferBanner || shape === 'banner') && item.ImageTags?.Banner) {
imgType = 'Banner';
imgTag = item.ImageTags.Banner;
} else if (options.preferDisc && item.ImageTags && item.ImageTags.Disc) {
} else if (options.preferDisc && item.ImageTags?.Disc) {
imgType = 'Disc';
imgTag = item.ImageTags.Disc;
} else if (options.preferLogo && item.ImageTags && item.ImageTags.Logo) {
} else if (options.preferLogo && item.ImageTags?.Logo) {
imgType = 'Logo';
imgTag = item.ImageTags.Logo;
} else if (options.preferLogo && item.ParentLogoImageTag && item.ParentLogoItemId) {
@ -301,11 +301,11 @@ export function getCardImageUrl(item, apiClient, options, shape) {
imgType = 'Thumb';
imgTag = item.ParentThumbImageTag;
itemId = item.ParentThumbItemId;
} else if (options.preferThumb && item.BackdropImageTags && item.BackdropImageTags.length) {
} else if (options.preferThumb && item.BackdropImageTags?.length) {
imgType = 'Backdrop';
imgTag = item.BackdropImageTags[0];
forceName = true;
} else if (options.preferThumb && item.ParentBackdropImageTags && item.ParentBackdropImageTags.length && options.inheritThumb !== false && item.Type === 'Episode') {
} else if (options.preferThumb && item.ParentBackdropImageTags?.length && options.inheritThumb !== false && item.Type === 'Episode') {
imgType = 'Backdrop';
imgTag = item.ParentBackdropImageTags[0];
itemId = item.ParentBackdropItemId;
@ -351,7 +351,7 @@ export function getCardImageUrl(item, apiClient, options, shape) {
if (primaryImageAspectRatio && uiAspect) {
coverImage = (Math.abs(primaryImageAspectRatio - uiAspect) / uiAspect) <= 0.2;
}
} else if (item.Type === 'Season' && item.ImageTags && item.ImageTags.Thumb) {
} else if (item.Type === 'Season' && item.ImageTags?.Thumb) {
imgType = 'Thumb';
imgTag = item.ImageTags.Thumb;
} else if (item.BackdropImageTags?.length) {
@ -571,7 +571,7 @@ function getCardFooterText(item, apiClient, options, footerClass, progressHtml,
if (showOtherText) {
if (options.showParentTitle && parentTitleUnderneath) {
if (flags.isOuterFooter && item.AlbumArtists && item.AlbumArtists.length) {
if (flags.isOuterFooter && item.AlbumArtists?.length) {
item.AlbumArtists[0].Type = 'MusicArtist';
item.AlbumArtists[0].IsFolder = true;
lines.push(getTextActionButton(item.AlbumArtists[0], null, serverId));

View file

@ -152,7 +152,7 @@ export function seekOnPlaybackStart(instance, element, ticks, onMediaReady) {
}
export function applySrc(elem, src, options) {
if (window.Windows && options.mediaSource && options.mediaSource.IsLocal) {
if (window.Windows && options.mediaSource?.IsLocal) {
return Windows.Storage.StorageFile.getFileFromPathAsync(options.url).then(function (file) {
const playlist = new Windows.Media.Playback.MediaPlaybackList();

View file

@ -316,7 +316,7 @@ export function getCommands(options) {
}
// Show Album Artist by default, as a song can have multiple artists, which specific one would this option refer to?
// Although some albums can have multiple artists, it's not as common as songs.
if (options.openArtist !== false && item.AlbumArtists && item.AlbumArtists.length) {
if (options.openArtist !== false && item.AlbumArtists?.length) {
commands.push({
name: globalize.translate('ViewAlbumArtist'),
id: 'artist',
@ -609,7 +609,7 @@ function play(item, resume, queue, queueNext) {
}
let startPosition = 0;
if (resume && item.UserData && item.UserData.PlaybackPositionTicks) {
if (resume && item.UserData?.PlaybackPositionTicks) {
startPosition = item.UserData.PlaybackPositionTicks;
}

View file

@ -64,7 +64,7 @@ function getMediaSourceHtml(user, item, version) {
if (version.Formats?.length) {
html += `${createAttribute(globalize.translate('MediaInfoFormat'), version.Formats.join(','))}<br/>`;
}
if (version.Path && user && user.Policy.IsAdministrator) {
if (version.Path && user?.Policy.IsAdministrator) {
html += `${createAttribute(globalize.translate('MediaInfoPath'), version.Path, true)}<br/>`;
}
if (version.Size) {

View file

@ -737,12 +737,12 @@ export default function () {
}
});
context.querySelector('.btnAudioTracks').addEventListener('click', function (e) {
if (currentPlayer && lastPlayerState && lastPlayerState.NowPlayingItem) {
if (currentPlayer && lastPlayerState?.NowPlayingItem) {
showAudioMenu(context, currentPlayer, e.target);
}
});
context.querySelector('.btnSubtitles').addEventListener('click', function (e) {
if (currentPlayer && lastPlayerState && lastPlayerState.NowPlayingItem) {
if (currentPlayer && lastPlayerState?.NowPlayingItem) {
showSubtitleMenu(context, currentPlayer, e.target);
}
});

View file

@ -92,7 +92,7 @@ function getImgUrl(item, user) {
if (item.BackdropImageTags?.length) {
return getBackdropImageUrl(item, imageOptions, apiClient);
} else {
if (item.MediaType === 'Photo' && user && user.Policy.EnableContentDownloading) {
if (item.MediaType === 'Photo' && user?.Policy.EnableContentDownloading) {
return apiClient.getItemDownloadUrl(item.Id);
}
imageOptions.type = 'Primary';
@ -171,7 +171,7 @@ export default function (options) {
if (actionButtonsOnTop) {
html += getIcon('play_arrow', 'btnSlideshowPause slideshowButton', true);
if (appHost.supports('filedownload') && slideshowOptions.user && slideshowOptions.user.Policy.EnableContentDownloading) {
if (appHost.supports('filedownload') && slideshowOptions.user?.Policy.EnableContentDownloading) {
html += getIcon('file_download', 'btnDownload slideshowButton', true);
}
if (appHost.supports('sharing')) {
@ -189,7 +189,7 @@ export default function (options) {
html += '<div class="slideshowBottomBar hide">';
html += getIcon('play_arrow', 'btnSlideshowPause slideshowButton', true, true);
if (appHost.supports('filedownload') && slideshowOptions.user && slideshowOptions.user.Policy.EnableContentDownloading) {
if (appHost.supports('filedownload') && slideshowOptions?.user.Policy.EnableContentDownloading) {
html += getIcon('file_download', 'btnDownload slideshowButton', true);
}
if (appHost.supports('sharing')) {

View file

@ -293,7 +293,7 @@ const scrollerFactory = function (frame, options) {
immediate = true;
}
if (!immediate && o.skipSlideToWhenVisible && fullItemPos && fullItemPos.isVisible) {
if (!immediate && o.skipSlideToWhenVisible && fullItemPos?.isVisible) {
return;
}

View file

@ -716,7 +716,7 @@ class ChromecastPlayer {
});
}
if (options.items.length > 1 && options && options.ids) {
if (options.items.length > 1 && options?.ids) {
// Use the original request id array for sorting the result in the proper order
options.items.sort(function (a, b) {
return options.ids.indexOf(a.Id) - options.ids.indexOf(b.Id);

View file

@ -105,7 +105,7 @@ function mergePlaybackQueries(obj1, obj2) {
}
export function translateItemsForPlayback(apiClient, items, options) {
if (items.length > 1 && options && options.ids) {
if (items.length > 1 && options?.ids) {
// Use the original request id array for sorting the result in the proper order.
items.sort(function (a, b) {
return options.ids.indexOf(a.Id) - options.ids.indexOf(b.Id);