Fix UIRenderer constructor to properly accept and assign 'player' instance
Resolved TypeError where 'this.player' was undefined in UIRenderer, preventing 'isCurrentTrack' check from working correctly. Updated constructor to accept 'player' argument passed from app.js.
This commit is contained in:
parent
2ae6b620f2
commit
45380ea148
2 changed files with 48 additions and 48 deletions
|
|
@ -175,12 +175,12 @@ function hideOfflineNotification() {
|
|||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
const api = new LosslessAPI(apiSettings);
|
||||
const ui = new UIRenderer(api);
|
||||
|
||||
const audioPlayer = document.getElementById('audio-player');
|
||||
const currentQuality = localStorage.getItem('playback-quality') || 'LOSSLESS';
|
||||
const player = new Player(audioPlayer, api, currentQuality);
|
||||
|
||||
const ui = new UIRenderer(api, player);
|
||||
const scrobbler = new LastFMScrobbler();
|
||||
const lyricsManager = new LyricsManager(api);
|
||||
const lyricsPanel = createLyricsPanel();
|
||||
|
|
|
|||
12
js/ui.js
12
js/ui.js
|
|
@ -3,8 +3,9 @@ import { SVG_PLAY, SVG_DOWNLOAD, SVG_MENU, formatTime, createPlaceholder, trackD
|
|||
import { recentActivityManager, backgroundSettings, trackListSettings } from './storage.js';
|
||||
|
||||
export class UIRenderer {
|
||||
constructor(api) {
|
||||
constructor(api, player) {
|
||||
this.api = api;
|
||||
this.player = player;
|
||||
this.currentTrack = null;
|
||||
this.searchAbortController = null;
|
||||
}
|
||||
|
|
@ -72,6 +73,7 @@ export class UIRenderer {
|
|||
const explicitBadge = hasExplicitContent(track) ? this.createExplicitBadge() : '';
|
||||
const trackArtists = getTrackArtists(track);
|
||||
const trackTitle = getTrackTitle(track);
|
||||
const isCurrentTrack = this.player?.currentTrack?.id === track.id;
|
||||
|
||||
let yearDisplay = '';
|
||||
const releaseDate = track.album?.releaseDate || track.streamStartDate;
|
||||
|
|
@ -112,7 +114,7 @@ export class UIRenderer {
|
|||
`;
|
||||
|
||||
return `
|
||||
<div class="track-item" data-track-id="${track.id}">
|
||||
<div class="track-item ${isCurrentTrack ? 'playing' : ''}" data-track-id="${track.id}">
|
||||
${trackNumberHTML}
|
||||
<div class="track-item-info">
|
||||
<div class="track-item-details">
|
||||
|
|
@ -662,13 +664,11 @@ async renderPlaylistPage(playlistId) {
|
|||
imageEl.style.backgroundColor = '';
|
||||
|
||||
titleEl.textContent = playlist.title;
|
||||
|
||||
this.adjustTitleFontSize(titleEl, playlist.title);
|
||||
|
||||
const totalDuration = calculateTotalDuration(tracks);
|
||||
|
||||
metaEl.textContent = `${playlist.numberOfTracks} tracks • ${formatDuration(totalDuration)}`;
|
||||
|
||||
descEl.textContent = playlist.description || '';
|
||||
|
||||
tracklistContainer.innerHTML = `
|
||||
|
|
@ -680,10 +680,10 @@ async renderPlaylistPage(playlistId) {
|
|||
`;
|
||||
|
||||
this.renderListWithTracks(tracklistContainer, tracks, true);
|
||||
|
||||
recentActivityManager.addPlaylist(playlist);
|
||||
|
||||
document.title = `${playlist.title || 'Artist Mix'} - Monochrome`; } catch (error) {
|
||||
document.title = `${playlist.title || 'Artist Mix'} - Monochrome`;
|
||||
} catch (error) {
|
||||
console.error("Failed to load playlist:", error);
|
||||
tracklistContainer.innerHTML = createPlaceholder(`Could not load playlist details. ${error.message}`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue