Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace existence check with optional chaining #5742

Merged
merged 2 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/backdrop/backdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
16 changes: 8 additions & 8 deletions src/components/cardbuilder/cardBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/components/htmlMediaHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/components/itemContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/itemMediaInfo/itemMediaInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/remotecontrol/remotecontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
6 changes: 3 additions & 3 deletions src/components/slideshow/slideshow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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')) {
Expand All @@ -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')) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/scroller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/chromecastPlayer/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/syncPlay/core/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading