Skip to content

Commit 1cd5915

Browse files
Update main.js
1 parent 07041dc commit 1cd5915

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

public/js/main.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,41 @@ import { loadAndScheduleNotifications, subscribeUserToPush, navigateToProgramInG
1717
import { setupDvrEventListeners, handleDvrChannelClick, initDvrPage } from './modules/dvr.js';
1818
import { handleMultiViewChannelClick, populateChannelSelector, initMultiView } from './modules/multiview.js';
1919
import { setupDirectPlayerEventListeners, initDirectPlayer } from './modules/player_direct.js';
20+
import { ICONS } from './modules/icons.js'; // MODIFIED: Import the new icon library
2021

2122
// The initializeCastApi function is no longer called directly from here,
2223
// but the cast.js module will handle its own initialization via the window callback.
2324

2425
// NEW: Global variable to hold navigation target from a notification click
2526
let notificationTarget = null;
2627

28+
/**
29+
* NEW: Finds all icon placeholders in the document and injects the SVG markup.
30+
*/
31+
function renderIcons() {
32+
console.log('[MAIN] Rendering all icons from placeholders...');
33+
const iconPlaceholders = document.querySelectorAll('[data-icon]');
34+
iconPlaceholders.forEach(placeholder => {
35+
const iconName = placeholder.dataset.icon;
36+
if (ICONS[iconName]) {
37+
// Replace the placeholder itself with the SVG element
38+
const template = document.createElement('template');
39+
template.innerHTML = ICONS[iconName].trim();
40+
const svgElement = template.content.firstChild;
41+
42+
// Copy any existing classes from the placeholder to the SVG
43+
if (placeholder.className) {
44+
svgElement.classList.add(...placeholder.className.split(' '));
45+
}
46+
47+
// Replace the placeholder in the DOM
48+
placeholder.parentNode.replaceChild(svgElement, placeholder);
49+
} else {
50+
console.warn(`[ICONS] Icon not found in library: ${iconName}`);
51+
}
52+
});
53+
}
54+
2755

2856
/**
2957
* NEW: Connects to the server for real-time events using Server-Sent Events (SSE).
@@ -84,6 +112,9 @@ export async function initMainApp() {
84112
// The cast.js module will now be initialized automatically by the Google Cast SDK callback.
85113
console.log('[MAIN] All event listeners set up.');
86114

115+
// MODIFIED: Render all icons now that the DOM is ready.
116+
renderIcons();
117+
87118
// 3. Load initial configuration and guide data
88119
try {
89120
console.log('[MAIN] Fetching initial configuration from server via api.js...');

0 commit comments

Comments
 (0)