diff --git a/static/app.js b/static/app.js index 37a76d9..982ef7e 100644 --- a/static/app.js +++ b/static/app.js @@ -1,6 +1,7 @@ // Define global variables to track music files and the current index. let currentMusicFiles = []; // Array of objects with at least { path, index } let currentMusicIndex = -1; // Index of the current music file +let currentTrackPath = ""; // Helper function: decode each segment then re-encode to avoid double encoding. function encodeSubpath(subpath) { @@ -15,6 +16,21 @@ function encodeSubpath(subpath) { let currentGalleryImages = []; +function paintFile() { + // Highlight the currently playing file + if (currentTrackPath) { + const currentMusicFile = currentMusicFiles.find(file => file.path === currentTrackPath); + if (currentMusicFile) { + const currentMusicFileElement = document.querySelector(`.play-file[data-url="${currentMusicFile.path}"]`); + if (currentMusicFileElement) { + currentMusicFileElement.closest('.file-item').classList.add('currently-playing'); + } + } else { + console.log('Current track not found in the updated list.'); + } + } + } + function renderContent(data) { // Render breadcrumbs, directories (grid view when appropriate), and files. @@ -62,9 +78,7 @@ function renderContent(data) { symbol = '🖼️'; } const indexAttr = file.file_type === 'music' ? ` data-index="${currentMusicFiles.length - 1}"` : ''; - // preserve currently-playing class during reloads - const isCurrentlyPlaying = file.file_type === 'music' && currentMusicIndex === currentMusicFiles.length - 1 ? ' currently-playing' : ''; - contentHTML += `