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

Add prefer optional chaining rule

This commit is contained in:
Bill Thornton 2023-07-06 13:39:48 -04:00
parent ec0adb895b
commit f35a8151e0
61 changed files with 152 additions and 152 deletions

View file

@ -47,7 +47,7 @@ function showPlaybackInfo(btn, session) {
text.push(globalize.translate('MediaIsBeingConverted'));
text.push(DashboardPage.getSessionNowPlayingStreamInfo(session));
if (session.TranscodingInfo && session.TranscodingInfo.TranscodeReasons && session.TranscodingInfo.TranscodeReasons.length) {
if (session.TranscodingInfo?.TranscodeReasons?.length) {
text.push('<br/>');
text.push(globalize.translate('LabelReasonForTranscoding'));
session.TranscodingInfo.TranscodeReasons.forEach(function (transcodeReason) {
@ -90,7 +90,7 @@ function showOptionsMenu(btn, session) {
});
}
if (session.TranscodingInfo && session.TranscodingInfo.TranscodeReasons && session.TranscodingInfo.TranscodeReasons.length) {
if (session.TranscodingInfo?.TranscodeReasons?.length) {
menuItems.push({
name: globalize.translate('ViewPlaybackInfo'),
id: 'transcodinginfo'
@ -402,7 +402,7 @@ window.DashboardPage = {
} else if (displayPlayMethod === 'DirectStream') {
html += globalize.translate('DirectStreaming');
} else if (displayPlayMethod === 'Transcode') {
if (session.TranscodingInfo && session.TranscodingInfo.Framerate) {
if (session.TranscodingInfo?.Framerate) {
html += `${globalize.translate('Framerate')}: ${session.TranscodingInfo.Framerate}fps`;
}
@ -481,7 +481,7 @@ window.DashboardPage = {
let topText = escapeHtml(itemHelper.getDisplayName(nowPlayingItem));
let bottomText = '';
if (nowPlayingItem.Artists && nowPlayingItem.Artists.length) {
if (nowPlayingItem.Artists?.length) {
bottomText = topText;
topText = escapeHtml(nowPlayingItem.Artists[0]);
} else {
@ -493,7 +493,7 @@ window.DashboardPage = {
}
}
if (nowPlayingItem.ImageTags && nowPlayingItem.ImageTags.Logo) {
if (nowPlayingItem.ImageTags?.Logo) {
imgUrl = ApiClient.getScaledImageUrl(nowPlayingItem.Id, {
tag: nowPlayingItem.ImageTags.Logo,
maxHeight: 24,
@ -571,7 +571,7 @@ window.DashboardPage = {
const btnSessionPlayPauseIcon = btnSessionPlayPause.querySelector('.material-icons');
btnSessionPlayPauseIcon.classList.remove('play_arrow', 'pause');
btnSessionPlayPauseIcon.classList.add(session.PlayState && session.PlayState.IsPaused ? 'play_arrow' : 'pause');
btnSessionPlayPauseIcon.classList.add(session.PlayState?.IsPaused ? 'play_arrow' : 'pause');
row.querySelector('.sessionNowPlayingTime').innerText = DashboardPage.getSessionNowPlayingTime(session);
row.querySelector('.sessionUserName').innerHTML = DashboardPage.getUsersHtml(session);
@ -620,7 +620,7 @@ window.DashboardPage = {
getNowPlayingImageUrl: function (item) {
/* Screen width is multiplied by 0.2, as the there is currently no way to get the width of
elements that aren't created yet. */
if (item && item.BackdropImageTags && item.BackdropImageTags.length) {
if (item?.BackdropImageTags?.length) {
return ApiClient.getScaledImageUrl(item.Id, {
maxWidth: Math.round(dom.getScreenWidth() * 0.20),
type: 'Backdrop',
@ -628,7 +628,7 @@ window.DashboardPage = {
});
}
if (item && item.ParentBackdropImageTags && item.ParentBackdropImageTags.length) {
if (item?.ParentBackdropImageTags?.length) {
return ApiClient.getScaledImageUrl(item.ParentBackdropItemId, {
maxWidth: Math.round(dom.getScreenWidth() * 0.20),
type: 'Backdrop',
@ -636,7 +636,7 @@ window.DashboardPage = {
});
}
if (item && item.BackdropImageTag) {
if (item?.BackdropImageTag) {
return ApiClient.getScaledImageUrl(item.BackdropItemId, {
maxWidth: Math.round(dom.getScreenWidth() * 0.20),
type: 'Backdrop',
@ -644,7 +644,7 @@ window.DashboardPage = {
});
}
const imageTags = (item || {}).ImageTags || {};
const imageTags = item?.ImageTags || {};
if (item && imageTags.Thumb) {
return ApiClient.getScaledImageUrl(item.Id, {
@ -654,7 +654,7 @@ window.DashboardPage = {
});
}
if (item && item.ParentThumbImageTag) {
if (item?.ParentThumbImageTag) {
return ApiClient.getScaledImageUrl(item.ParentThumbItemId, {
maxWidth: Math.round(dom.getScreenWidth() * 0.20),
type: 'Thumb',
@ -662,7 +662,7 @@ window.DashboardPage = {
});
}
if (item && item.ThumbImageTag) {
if (item?.ThumbImageTag) {
return ApiClient.getScaledImageUrl(item.ThumbItemId, {
maxWidth: Math.round(dom.getScreenWidth() * 0.20),
type: 'Thumb',
@ -678,7 +678,7 @@ window.DashboardPage = {
});
}
if (item && item.PrimaryImageTag) {
if (item?.PrimaryImageTag) {
return ApiClient.getScaledImageUrl(item.PrimaryImageItemId, {
maxWidth: Math.round(dom.getScreenWidth() * 0.20),
type: 'Primary',
@ -686,7 +686,7 @@ window.DashboardPage = {
});
}
if (item && item.AlbumPrimaryImageTag) {
if (item?.AlbumPrimaryImageTag) {
return ApiClient.getScaledImageUrl(item.AlbumId, {
maxWidth: Math.round(dom.getScreenWidth() * 0.20),
type: 'Primary',

View file

@ -415,7 +415,7 @@ function renderContainerProfiles(page, profiles) {
html += '<a is="emby-linkbutton" href="#" class="lnkEditSubProfile" data-profileindex="' + i + '">';
html += '<p>' + globalize.translate('ValueContainer', profile.Container || allText) + '</p>';
if (profile.Conditions && profile.Conditions.length) {
if (profile.Conditions?.length) {
html += '<p>';
html += globalize.translate('ValueConditions', profile.Conditions.map(function (c) {
return c.Property;
@ -487,7 +487,7 @@ function renderCodecProfiles(page, profiles) {
html += '<a is="emby-linkbutton" href="#" class="lnkEditSubProfile" data-profileindex="' + i + '">';
html += '<p>' + globalize.translate('ValueCodec', profile.Codec || allText) + '</p>';
if (profile.Conditions && profile.Conditions.length) {
if (profile.Conditions?.length) {
html += '<p>';
html += globalize.translate('ValueConditions', profile.Conditions.map(function (c) {
return c.Property;
@ -567,7 +567,7 @@ function renderResponseProfiles(page, profiles) {
}
}
if (profile.Conditions && profile.Conditions.length) {
if (profile.Conditions?.length) {
html += '<p>';
html += globalize.translate('ValueConditions', profile.Conditions.map(function (c) {
return c.Property;

View file

@ -406,7 +406,7 @@ function renderName(item, container, context) {
if (item.AlbumArtists) {
parentNameHtml.push(getArtistLinksHtml(item.AlbumArtists, item.ServerId, context));
parentNameLast = true;
} else if (item.ArtistItems && item.ArtistItems.length && item.Type === 'MusicVideo') {
} else if (item.ArtistItems?.length && item.Type === 'MusicVideo') {
parentNameHtml.push(getArtistLinksHtml(item.ArtistItems, item.ServerId, context));
parentNameLast = true;
} else if (item.SeriesName && item.Type === 'Episode') {
@ -475,7 +475,7 @@ function renderName(item, container, context) {
}
function setTrailerButtonVisibility(page, item) {
if ((item.LocalTrailerCount || item.RemoteTrailers && item.RemoteTrailers.length) && playbackManager.getSupportedCommands().indexOf('PlayTrailers') !== -1) {
if ((item.LocalTrailerCount || item.RemoteTrailers?.length) && playbackManager.getSupportedCommands().indexOf('PlayTrailers') !== -1) {
hideAll(page, 'btnPlayTrailer', true);
} else {
hideAll(page, 'btnPlayTrailer');
@ -505,7 +505,7 @@ function renderDetailPageBackdrop(page, item, apiClient) {
let hasbackdrop = false;
const itemBackdropElement = page.querySelector('#itemBackdrop');
if (item.BackdropImageTags && item.BackdropImageTags.length) {
if (item.BackdropImageTags?.length) {
imgUrl = apiClient.getScaledImageUrl(item.Id, {
type: 'Backdrop',
maxWidth: dom.getScreenWidth(),
@ -523,7 +523,7 @@ function renderDetailPageBackdrop(page, item, apiClient) {
});
imageLoader.lazyImage(itemBackdropElement, imgUrl);
hasbackdrop = true;
} else if (item.ImageTags && item.ImageTags.Primary) {
} else if (item.ImageTags?.Primary) {
imgUrl = apiClient.getScaledImageUrl(item.Id, {
type: 'Primary',
maxWidth: dom.getScreenWidth(),
@ -660,7 +660,7 @@ function logoImageUrl(item, apiClient, options) {
options = options || {};
options.type = 'Logo';
if (item.ImageTags && item.ImageTags.Logo) {
if (item.ImageTags?.Logo) {
options.tag = item.ImageTags.Logo;
return apiClient.getScaledImageUrl(item.Id, options);
}
@ -1054,7 +1054,7 @@ function renderMiscInfo(page, item) {
function renderTagline(page, item) {
const taglineElement = page.querySelector('.tagline');
if (item.Taglines && item.Taglines.length) {
if (item.Taglines?.length) {
taglineElement.classList.remove('hide');
taglineElement.innerHTML = '<bdi>' + escapeHtml(item.Taglines[0]) + '</bdi>';
} else {
@ -1263,7 +1263,7 @@ function renderSeriesAirTime(page, item) {
return;
}
let html = '';
if (item.AirDays && item.AirDays.length) {
if (item.AirDays?.length) {
if (item.AirDays.length == 7) {
html += 'daily';
} else {

View file

@ -229,7 +229,7 @@ export default function (view, params) {
function onTabChange(evt) {
const previousTabController = tabControllers[parseInt(evt.detail.previousIndex, 10)];
if (previousTabController && previousTabController.onHide) {
if (previousTabController?.onHide) {
previousTabController.onHide();
}
@ -388,7 +388,7 @@ export default function (view, params) {
inputManager.on(window, onInputCommand);
});
view.addEventListener('viewbeforehide', function () {
if (currentTabController && currentTabController.onHide) {
if (currentTabController?.onHide) {
currentTabController.onHide();
}

View file

@ -666,7 +666,7 @@ export default function (view) {
if (item.Type === 'TvChannel') {
const program = item.CurrentProgram;
if (program && program.EndDate) {
if (program?.EndDate) {
try {
const endDate = datetime.parseISO8601Date(program.EndDate);
@ -1685,7 +1685,7 @@ export default function (view) {
ticks *= value;
const item = currentItem;
if (item && item.Chapters && item.Chapters.length && item.Chapters[0].ImageTag) {
if (item?.Chapters?.length && item.Chapters[0].ImageTag) {
const html = getChapterBubbleHtml(ServerConnections.getApiClient(item.ServerId), item, item.Chapters, ticks);
if (html) {