style(js): correct linter main warnings

This commit is contained in:
Edouard Vanbelle
2026-04-11 18:27:54 +02:00
parent c7eeb734d7
commit 13aa90cf3c
2 changed files with 26 additions and 24 deletions
+7 -5
View File
@@ -55,9 +55,9 @@ const contextMenus = {
const option = document.getElementById('add-to-playlist-option');
if (!option) return;
const targetFile = window.app && window.app.contextMenuTargetFile;
const targetFile = window.app?.contextMenuTargetFile;
if (targetFile) {
const isAudio = targetFile.mime_type && targetFile.mime_type.startsWith('audio/');
const isAudio = targetFile.mime_type?.startsWith('audio/');
option.classList.toggle('hidden', !isAudio);
} else {
option.classList.add('hidden');
@@ -1142,7 +1142,9 @@ const contextMenus = {
`;
item.addEventListener('click', () => {
container.querySelectorAll('.folder-select-item').forEach((el) => el.classList.remove('selected'));
container.querySelectorAll('.folder-select-item').forEach((el) => {
el.classList.remove('selected');
});
item.classList.add('selected');
this._selectedPlaylistId = playlist.id;
const addBtn = document.getElementById('playlist-add-btn');
@@ -1178,7 +1180,7 @@ const contextMenus = {
throw new Error(err.message || 'Failed to add tracks');
}
const result = await resp.json();
await resp.json();
window.ui.showNotification(
window.i18n ? window.i18n.t('music.added', 'Added!') : 'Added!',
`${files.length} ${files.length === 1 ? 'track' : 'tracks'} ${window.i18n ? window.i18n.t('music.added_to_playlist', 'added to playlist') : 'added to playlist'}`
@@ -1187,7 +1189,7 @@ const contextMenus = {
this.closePlaylistDialog();
// Refresh music view if open
if (window.musicView && window.musicView.playlists) {
if (window.musicView?.playlists) {
window.musicView._loadPlaylists();
}
} catch (err) {
+19 -19
View File
@@ -391,26 +391,24 @@ const musicView = {
)
.join('')}
`;
const self = this;
trackListEl.querySelectorAll('.music-track').forEach((row) => {
row.addEventListener('click', () => {
const idx = parseInt(row.dataset.idx);
const idx = parseInt(row.dataset.idx, 10);
// Toggle selection
trackListEl.querySelectorAll('.music-track').forEach((r) => {
if (r !== row) r.classList.remove('selected');
});
row.classList.toggle('selected');
self.selected.clear();
this.selected.clear();
if (row.classList.contains('selected')) {
self.selected.add(idx);
this.selected.add(idx);
}
});
row.addEventListener('dblclick', (e) => {
e.preventDefault();
const idx = parseInt(row.dataset.idx);
self._playTrack(idx);
const idx = parseInt(row.dataset.idx, 10);
this._playTrack(idx);
});
// Drag & drop
@@ -421,7 +419,9 @@ const musicView = {
});
row.addEventListener('dragend', () => {
row.classList.remove('dragging');
trackListEl.querySelectorAll('.music-track').forEach((r) => r.classList.remove('drag-over'));
trackListEl.querySelectorAll('.music-track').forEach((r) => {
r.classList.remove('drag-over');
});
});
row.addEventListener('dragover', (e) => {
e.preventDefault();
@@ -437,10 +437,10 @@ const musicView = {
row.addEventListener('drop', (e) => {
e.preventDefault();
row.classList.remove('drag-over');
const fromIdx = parseInt(e.dataTransfer.getData('text/plain'));
const toIdx = parseInt(row.dataset.idx);
const fromIdx = parseInt(e.dataTransfer.getData('text/plain'), 10);
const toIdx = parseInt(row.dataset.idx, 10);
if (fromIdx !== toIdx) {
self._reorderTrack(fromIdx, toIdx);
this._reorderTrack(fromIdx, toIdx);
}
});
@@ -449,7 +449,7 @@ const musicView = {
if (removeBtn) {
removeBtn.addEventListener('click', (e) => {
e.stopPropagation();
self._removeTrackFromPlaylist(row.dataset.id, row.dataset.fileId);
this._removeTrackFromPlaylist(row.dataset.id, row.dataset.fileId);
});
}
});
@@ -499,7 +499,7 @@ const musicView = {
icon: 'fa-music',
confirmText: t('music.create', 'Create')
});
if (!name || !name.trim()) return;
if (!name?.trim()) return;
this._createPlaylist(name.trim());
},
@@ -653,7 +653,7 @@ const musicView = {
icon: 'fa-pen',
confirmText: t('actions.confirm', 'Save')
});
if (!newName || !newName.trim() || newName.trim() === this.currentPlaylist.name) return;
if (!newName?.trim() || newName.trim() === this.currentPlaylist.name) return;
try {
const resp = await fetch(`/api/playlists/${this.currentPlaylist.id}`, {
@@ -699,7 +699,7 @@ const musicView = {
icon: 'fa-share-alt',
confirmText: t('music.share', 'Share')
});
if (!userId || !userId.trim()) return;
if (!userId?.trim()) return;
try {
const resp = await fetch(`/api/playlists/${this.currentPlaylist.id}/share`, {
@@ -1619,7 +1619,7 @@ const musicPlayer = {
if (musicView.currentTracks.length > 0) {
document.querySelectorAll('.music-track').forEach((row) => {
const idx = parseInt(row.dataset.idx);
const idx = parseInt(row.dataset.idx, 10);
row.classList.toggle('playing', idx === this.currentIndex && this.isPlaying);
const numText = row.querySelector('.track-num-text');
@@ -1695,7 +1695,7 @@ const musicPlayer = {
queueList.querySelectorAll('.player-queue-item').forEach((item) => {
item.addEventListener('click', (e) => {
if (e.target.closest('.queue-item-remove')) return;
const idx = parseInt(item.dataset.idx);
const idx = parseInt(item.dataset.idx, 10);
this.playTrack(idx);
});
});
@@ -1703,7 +1703,7 @@ const musicPlayer = {
queueList.querySelectorAll('.queue-item-remove').forEach((btn) => {
btn.addEventListener('click', (e) => {
e.stopPropagation();
const idx = parseInt(btn.dataset.idx);
const idx = parseInt(btn.dataset.idx, 10);
this._removeFromQueue(idx);
});
});
@@ -1748,7 +1748,7 @@ const musicPlayer = {
},
_formatTime(secs) {
if (!secs || isNaN(secs)) return '0:00';
if (!secs || Number.isNaN(secs)) return '0:00';
const mins = Math.floor(secs / 60);
const s = Math.floor(secs % 60);
return `${mins}:${s.toString().padStart(2, '0')}`;