style(js): correct linter main warnings
This commit is contained in:
@@ -55,9 +55,9 @@ const contextMenus = {
|
|||||||
const option = document.getElementById('add-to-playlist-option');
|
const option = document.getElementById('add-to-playlist-option');
|
||||||
if (!option) return;
|
if (!option) return;
|
||||||
|
|
||||||
const targetFile = window.app && window.app.contextMenuTargetFile;
|
const targetFile = window.app?.contextMenuTargetFile;
|
||||||
if (targetFile) {
|
if (targetFile) {
|
||||||
const isAudio = targetFile.mime_type && targetFile.mime_type.startsWith('audio/');
|
const isAudio = targetFile.mime_type?.startsWith('audio/');
|
||||||
option.classList.toggle('hidden', !isAudio);
|
option.classList.toggle('hidden', !isAudio);
|
||||||
} else {
|
} else {
|
||||||
option.classList.add('hidden');
|
option.classList.add('hidden');
|
||||||
@@ -1142,7 +1142,9 @@ const contextMenus = {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
item.addEventListener('click', () => {
|
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');
|
item.classList.add('selected');
|
||||||
this._selectedPlaylistId = playlist.id;
|
this._selectedPlaylistId = playlist.id;
|
||||||
const addBtn = document.getElementById('playlist-add-btn');
|
const addBtn = document.getElementById('playlist-add-btn');
|
||||||
@@ -1178,7 +1180,7 @@ const contextMenus = {
|
|||||||
throw new Error(err.message || 'Failed to add tracks');
|
throw new Error(err.message || 'Failed to add tracks');
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await resp.json();
|
await resp.json();
|
||||||
window.ui.showNotification(
|
window.ui.showNotification(
|
||||||
window.i18n ? window.i18n.t('music.added', 'Added!') : 'Added!',
|
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'}`
|
`${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();
|
this.closePlaylistDialog();
|
||||||
|
|
||||||
// Refresh music view if open
|
// Refresh music view if open
|
||||||
if (window.musicView && window.musicView.playlists) {
|
if (window.musicView?.playlists) {
|
||||||
window.musicView._loadPlaylists();
|
window.musicView._loadPlaylists();
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -391,26 +391,24 @@ const musicView = {
|
|||||||
)
|
)
|
||||||
.join('')}
|
.join('')}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const self = this;
|
|
||||||
trackListEl.querySelectorAll('.music-track').forEach((row) => {
|
trackListEl.querySelectorAll('.music-track').forEach((row) => {
|
||||||
row.addEventListener('click', () => {
|
row.addEventListener('click', () => {
|
||||||
const idx = parseInt(row.dataset.idx);
|
const idx = parseInt(row.dataset.idx, 10);
|
||||||
// Toggle selection
|
// Toggle selection
|
||||||
trackListEl.querySelectorAll('.music-track').forEach((r) => {
|
trackListEl.querySelectorAll('.music-track').forEach((r) => {
|
||||||
if (r !== row) r.classList.remove('selected');
|
if (r !== row) r.classList.remove('selected');
|
||||||
});
|
});
|
||||||
row.classList.toggle('selected');
|
row.classList.toggle('selected');
|
||||||
self.selected.clear();
|
this.selected.clear();
|
||||||
if (row.classList.contains('selected')) {
|
if (row.classList.contains('selected')) {
|
||||||
self.selected.add(idx);
|
this.selected.add(idx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
row.addEventListener('dblclick', (e) => {
|
row.addEventListener('dblclick', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const idx = parseInt(row.dataset.idx);
|
const idx = parseInt(row.dataset.idx, 10);
|
||||||
self._playTrack(idx);
|
this._playTrack(idx);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Drag & drop
|
// Drag & drop
|
||||||
@@ -421,7 +419,9 @@ const musicView = {
|
|||||||
});
|
});
|
||||||
row.addEventListener('dragend', () => {
|
row.addEventListener('dragend', () => {
|
||||||
row.classList.remove('dragging');
|
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) => {
|
row.addEventListener('dragover', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -437,10 +437,10 @@ const musicView = {
|
|||||||
row.addEventListener('drop', (e) => {
|
row.addEventListener('drop', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
row.classList.remove('drag-over');
|
row.classList.remove('drag-over');
|
||||||
const fromIdx = parseInt(e.dataTransfer.getData('text/plain'));
|
const fromIdx = parseInt(e.dataTransfer.getData('text/plain'), 10);
|
||||||
const toIdx = parseInt(row.dataset.idx);
|
const toIdx = parseInt(row.dataset.idx, 10);
|
||||||
if (fromIdx !== toIdx) {
|
if (fromIdx !== toIdx) {
|
||||||
self._reorderTrack(fromIdx, toIdx);
|
this._reorderTrack(fromIdx, toIdx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -449,7 +449,7 @@ const musicView = {
|
|||||||
if (removeBtn) {
|
if (removeBtn) {
|
||||||
removeBtn.addEventListener('click', (e) => {
|
removeBtn.addEventListener('click', (e) => {
|
||||||
e.stopPropagation();
|
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',
|
icon: 'fa-music',
|
||||||
confirmText: t('music.create', 'Create')
|
confirmText: t('music.create', 'Create')
|
||||||
});
|
});
|
||||||
if (!name || !name.trim()) return;
|
if (!name?.trim()) return;
|
||||||
|
|
||||||
this._createPlaylist(name.trim());
|
this._createPlaylist(name.trim());
|
||||||
},
|
},
|
||||||
@@ -653,7 +653,7 @@ const musicView = {
|
|||||||
icon: 'fa-pen',
|
icon: 'fa-pen',
|
||||||
confirmText: t('actions.confirm', 'Save')
|
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 {
|
try {
|
||||||
const resp = await fetch(`/api/playlists/${this.currentPlaylist.id}`, {
|
const resp = await fetch(`/api/playlists/${this.currentPlaylist.id}`, {
|
||||||
@@ -699,7 +699,7 @@ const musicView = {
|
|||||||
icon: 'fa-share-alt',
|
icon: 'fa-share-alt',
|
||||||
confirmText: t('music.share', 'Share')
|
confirmText: t('music.share', 'Share')
|
||||||
});
|
});
|
||||||
if (!userId || !userId.trim()) return;
|
if (!userId?.trim()) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await fetch(`/api/playlists/${this.currentPlaylist.id}/share`, {
|
const resp = await fetch(`/api/playlists/${this.currentPlaylist.id}/share`, {
|
||||||
@@ -1619,7 +1619,7 @@ const musicPlayer = {
|
|||||||
|
|
||||||
if (musicView.currentTracks.length > 0) {
|
if (musicView.currentTracks.length > 0) {
|
||||||
document.querySelectorAll('.music-track').forEach((row) => {
|
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);
|
row.classList.toggle('playing', idx === this.currentIndex && this.isPlaying);
|
||||||
|
|
||||||
const numText = row.querySelector('.track-num-text');
|
const numText = row.querySelector('.track-num-text');
|
||||||
@@ -1695,7 +1695,7 @@ const musicPlayer = {
|
|||||||
queueList.querySelectorAll('.player-queue-item').forEach((item) => {
|
queueList.querySelectorAll('.player-queue-item').forEach((item) => {
|
||||||
item.addEventListener('click', (e) => {
|
item.addEventListener('click', (e) => {
|
||||||
if (e.target.closest('.queue-item-remove')) return;
|
if (e.target.closest('.queue-item-remove')) return;
|
||||||
const idx = parseInt(item.dataset.idx);
|
const idx = parseInt(item.dataset.idx, 10);
|
||||||
this.playTrack(idx);
|
this.playTrack(idx);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1703,7 +1703,7 @@ const musicPlayer = {
|
|||||||
queueList.querySelectorAll('.queue-item-remove').forEach((btn) => {
|
queueList.querySelectorAll('.queue-item-remove').forEach((btn) => {
|
||||||
btn.addEventListener('click', (e) => {
|
btn.addEventListener('click', (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const idx = parseInt(btn.dataset.idx);
|
const idx = parseInt(btn.dataset.idx, 10);
|
||||||
this._removeFromQueue(idx);
|
this._removeFromQueue(idx);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1748,7 +1748,7 @@ const musicPlayer = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_formatTime(secs) {
|
_formatTime(secs) {
|
||||||
if (!secs || isNaN(secs)) return '0:00';
|
if (!secs || Number.isNaN(secs)) return '0:00';
|
||||||
const mins = Math.floor(secs / 60);
|
const mins = Math.floor(secs / 60);
|
||||||
const s = Math.floor(secs % 60);
|
const s = Math.floor(secs % 60);
|
||||||
return `${mins}:${s.toString().padStart(2, '0')}`;
|
return `${mins}:${s.toString().padStart(2, '0')}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user