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

Fix sonarjs no-identical-functions

This commit is contained in:
Bill Thornton 2022-10-05 15:31:15 -04:00
parent 8472112951
commit 4972f50a06
8 changed files with 45 additions and 94 deletions

View file

@ -76,7 +76,6 @@ module.exports = {
'sonarjs/cognitive-complexity': ['warn'], 'sonarjs/cognitive-complexity': ['warn'],
// TODO: Enable the following rules and fix issues // TODO: Enable the following rules and fix issues
'sonarjs/no-duplicate-string': ['off'], 'sonarjs/no-duplicate-string': ['off'],
'sonarjs/no-identical-functions': ['off'],
'sonarjs/no-redundant-jump': ['off'], 'sonarjs/no-redundant-jump': ['off'],
'sonarjs/no-small-switch': ['off'], 'sonarjs/no-small-switch': ['off'],
'sonarjs/prefer-object-literal': ['off'], 'sonarjs/prefer-object-literal': ['off'],

View file

@ -275,6 +275,11 @@ import '../../assets/css/scrollstyles.scss';
} }
} }
const getAnimationEndHandler = (dlg, callback) => function handler() {
dom.removeEventListener(dlg, dom.whichAnimationEvent(), handler, { once: true });
callback();
};
function animateDialogOpen(dlg) { function animateDialogOpen(dlg) {
const onAnimationFinish = () => { const onAnimationFinish = () => {
focusManager.pushScope(dlg); focusManager.pushScope(dlg);
@ -290,15 +295,11 @@ import '../../assets/css/scrollstyles.scss';
}; };
if (enableAnimation()) { if (enableAnimation()) {
const onFinish = () => { dom.addEventListener(
dom.removeEventListener(dlg, dom.whichAnimationEvent(), onFinish, { dlg,
once: true dom.whichAnimationEvent(),
}); getAnimationEndHandler(dlg, onAnimationFinish),
onAnimationFinish(); { once: true });
};
dom.addEventListener(dlg, dom.whichAnimationEvent(), onFinish, {
once: true
});
return; return;
} }
@ -324,15 +325,12 @@ import '../../assets/css/scrollstyles.scss';
animated = false; animated = false;
break; break;
} }
const onFinish = () => {
dom.removeEventListener(dlg, dom.whichAnimationEvent(), onFinish, { dom.addEventListener(
once: true dlg,
}); dom.whichAnimationEvent(),
onAnimationFinish(); getAnimationEndHandler(dlg, onAnimationFinish),
}; { once: true });
dom.addEventListener(dlg, dom.whichAnimationEvent(), onFinish, {
once: true
});
if (animated) { if (animated) {
return; return;

View file

@ -24,37 +24,18 @@ function getEventsToMonitor(instance) {
return []; return [];
} }
function onTimerCreated() { function notifyTimerRefresh() {
const instance = this; const instance = this;
if (getEventsToMonitor(instance).indexOf('timers') !== -1) { if (getEventsToMonitor(instance).indexOf('timers') !== -1) {
instance.notifyRefreshNeeded(); instance.notifyRefreshNeeded();
return;
} }
} }
function onSeriesTimerCreated() { function notifySeriesTimerRefresh() {
const instance = this; const instance = this;
if (getEventsToMonitor(instance).indexOf('seriestimers') !== -1) { if (getEventsToMonitor(instance).indexOf('seriestimers') !== -1) {
instance.notifyRefreshNeeded(); instance.notifyRefreshNeeded();
return;
}
}
function onTimerCancelled() {
const instance = this;
if (getEventsToMonitor(instance).indexOf('timers') !== -1) {
instance.notifyRefreshNeeded();
return;
}
}
function onSeriesTimerCancelled() {
const instance = this;
if (getEventsToMonitor(instance).indexOf('seriestimers') !== -1) {
instance.notifyRefreshNeeded();
return;
} }
} }
@ -125,10 +106,10 @@ class ItemsRefresher {
this.options = options || {}; this.options = options || {};
addNotificationEvent(this, 'UserDataChanged', onUserDataChanged); addNotificationEvent(this, 'UserDataChanged', onUserDataChanged);
addNotificationEvent(this, 'TimerCreated', onTimerCreated); addNotificationEvent(this, 'TimerCreated', notifyTimerRefresh);
addNotificationEvent(this, 'SeriesTimerCreated', onSeriesTimerCreated); addNotificationEvent(this, 'SeriesTimerCreated', notifySeriesTimerRefresh);
addNotificationEvent(this, 'TimerCancelled', onTimerCancelled); addNotificationEvent(this, 'TimerCancelled', notifyTimerRefresh);
addNotificationEvent(this, 'SeriesTimerCancelled', onSeriesTimerCancelled); addNotificationEvent(this, 'SeriesTimerCancelled', notifySeriesTimerRefresh);
addNotificationEvent(this, 'LibraryChanged', onLibraryChanged); addNotificationEvent(this, 'LibraryChanged', onLibraryChanged);
addNotificationEvent(this, 'playbackstop', onPlaybackStopped, playbackManager); addNotificationEvent(this, 'playbackstop', onPlaybackStopped, playbackManager);
} }

View file

@ -747,14 +747,7 @@ import confirm from '../../components/confirm/confirm';
console.debug('onServerRestarting not implemented', evt, apiClient); console.debug('onServerRestarting not implemented', evt, apiClient);
} }
function onPackageInstalling(evt, apiClient) { function onPackageInstall(_, apiClient) {
if (apiClient.serverId() === serverId) {
pollForInfo(view, apiClient);
reloadSystemInfo(view, apiClient);
}
}
function onPackageInstallationCompleted(evt, apiClient) {
if (apiClient.serverId() === serverId) { if (apiClient.serverId() === serverId) {
pollForInfo(view, apiClient); pollForInfo(view, apiClient);
reloadSystemInfo(view, apiClient); reloadSystemInfo(view, apiClient);
@ -786,8 +779,8 @@ import confirm from '../../components/confirm/confirm';
Events.on(serverNotifications, 'RestartRequired', onRestartRequired); Events.on(serverNotifications, 'RestartRequired', onRestartRequired);
Events.on(serverNotifications, 'ServerShuttingDown', onServerShuttingDown); Events.on(serverNotifications, 'ServerShuttingDown', onServerShuttingDown);
Events.on(serverNotifications, 'ServerRestarting', onServerRestarting); Events.on(serverNotifications, 'ServerRestarting', onServerRestarting);
Events.on(serverNotifications, 'PackageInstalling', onPackageInstalling); Events.on(serverNotifications, 'PackageInstalling', onPackageInstall);
Events.on(serverNotifications, 'PackageInstallationCompleted', onPackageInstallationCompleted); Events.on(serverNotifications, 'PackageInstallationCompleted', onPackageInstall);
Events.on(serverNotifications, 'Sessions', onSessionsUpdate); Events.on(serverNotifications, 'Sessions', onSessionsUpdate);
Events.on(serverNotifications, 'ScheduledTasksInfo', onScheduledTasksUpdate); Events.on(serverNotifications, 'ScheduledTasksInfo', onScheduledTasksUpdate);
DashboardPage.lastAppUpdateCheck = null; DashboardPage.lastAppUpdateCheck = null;
@ -824,8 +817,8 @@ import confirm from '../../components/confirm/confirm';
Events.off(serverNotifications, 'RestartRequired', onRestartRequired); Events.off(serverNotifications, 'RestartRequired', onRestartRequired);
Events.off(serverNotifications, 'ServerShuttingDown', onServerShuttingDown); Events.off(serverNotifications, 'ServerShuttingDown', onServerShuttingDown);
Events.off(serverNotifications, 'ServerRestarting', onServerRestarting); Events.off(serverNotifications, 'ServerRestarting', onServerRestarting);
Events.off(serverNotifications, 'PackageInstalling', onPackageInstalling); Events.off(serverNotifications, 'PackageInstalling', onPackageInstall);
Events.off(serverNotifications, 'PackageInstallationCompleted', onPackageInstallationCompleted); Events.off(serverNotifications, 'PackageInstallationCompleted', onPackageInstall);
Events.off(serverNotifications, 'Sessions', onSessionsUpdate); Events.off(serverNotifications, 'Sessions', onSessionsUpdate);
Events.off(serverNotifications, 'ScheduledTasksInfo', onScheduledTasksUpdate); Events.off(serverNotifications, 'ScheduledTasksInfo', onScheduledTasksUpdate);

View file

@ -1204,17 +1204,6 @@ import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../../components
resetIdle(); resetIdle();
} }
function onWindowTouchStart(e) {
clickedElement = e.target;
mouseIsDown = true;
resetIdle();
}
function onWindowTouchEnd() {
mouseIsDown = false;
resetIdle();
}
function onWindowDragEnd() { function onWindowDragEnd() {
// mousedown -> dragstart -> dragend !!! no mouseup :( // mousedown -> dragstart -> dragend !!! no mouseup :(
mouseIsDown = false; mouseIsDown = false;
@ -1370,12 +1359,12 @@ import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../../components
capture: true, capture: true,
passive: true passive: true
}); });
dom.addEventListener(window, 'touchstart', onWindowTouchStart, { dom.addEventListener(window, 'touchstart', onWindowMouseDown, {
capture: true, capture: true,
passive: true passive: true
}); });
['touchend', 'touchcancel'].forEach((event) => { ['touchend', 'touchcancel'].forEach((event) => {
dom.addEventListener(window, event, onWindowTouchEnd, { dom.addEventListener(window, event, onWindowMouseUp, {
capture: true, capture: true,
passive: true passive: true
}); });
@ -1411,12 +1400,12 @@ import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../../components
capture: true, capture: true,
passive: true passive: true
}); });
dom.removeEventListener(window, 'touchstart', onWindowTouchStart, { dom.removeEventListener(window, 'touchstart', onWindowMouseDown, {
capture: true, capture: true,
passive: true passive: true
}); });
['touchend', 'touchcancel'].forEach((event) => { ['touchend', 'touchcancel'].forEach((event) => {
dom.removeEventListener(window, event, onWindowTouchEnd, { dom.removeEventListener(window, event, onWindowMouseUp, {
capture: true, capture: true,
passive: true passive: true
}); });

View file

@ -417,10 +417,7 @@ class HtmlAudioPlayer {
// This is a retry after error // This is a retry after error
resume() { resume() {
const mediaElement = this._mediaElement; this.unpause();
if (mediaElement) {
mediaElement.play();
}
} }
unpause() { unpause() {

View file

@ -1690,10 +1690,7 @@ function tryRemoveElement(elem) {
// This is a retry after error // This is a retry after error
resume() { resume() {
const mediaElement = this.#mediaElement; this.unpause();
if (mediaElement) {
mediaElement.play();
}
} }
unpause() { unpause() {

View file

@ -215,19 +215,7 @@ import { getParameterByName } from '../utils/url.ts';
} }
} }
function onNodeOpen(event, data) { function onNodeOpen(_, data) {
const page = $(this).parents('.page')[0];
const node = data.node;
if (node.children) {
loadNodesToLoad(page, node);
}
if (node.li_attr && node.id != '#' && !node.li_attr.loadedFromServer) {
node.li_attr.loadedFromServer = true;
$.jstree.reference('.libraryTree', page).load_node(node.id, loadNodeCallback);
}
}
function onNodeLoad(event, data) {
const page = $(this).parents('.page')[0]; const page = $(this).parents('.page')[0];
const node = data.node; const node = data.node;
if (node.children) { if (node.children) {
@ -254,7 +242,13 @@ import { getParameterByName } from '../utils/url.ts';
variant: 'large' variant: 'large'
} }
} }
}).off('select_node.jstree', onNodeSelect).on('select_node.jstree', onNodeSelect).off('open_node.jstree', onNodeOpen).on('open_node.jstree', onNodeOpen).off('load_node.jstree', onNodeLoad).on('load_node.jstree', onNodeLoad); })
.off('select_node.jstree', onNodeSelect)
.on('select_node.jstree', onNodeSelect)
.off('open_node.jstree', onNodeOpen)
.on('open_node.jstree', onNodeOpen)
.off('load_node.jstree', onNodeOpen)
.on('load_node.jstree', onNodeOpen);
} }
function loadNodesToLoad(page, node) { function loadNodesToLoad(page, node) {
@ -327,7 +321,10 @@ import { getParameterByName } from '../utils/url.ts';
}); });
}).on('pagebeforehide', '.metadataEditorPage', function () { }).on('pagebeforehide', '.metadataEditorPage', function () {
const page = this; const page = this;
$('.libraryTree', page).off('select_node.jstree', onNodeSelect).off('open_node.jstree', onNodeOpen).off('load_node.jstree', onNodeLoad); $('.libraryTree', page)
.off('select_node.jstree', onNodeSelect)
.off('open_node.jstree', onNodeOpen)
.off('load_node.jstree', onNodeOpen);
}); });
let itemId; let itemId;
window.MetadataEditor = { window.MetadataEditor = {