71 lines
2.0 KiB
JavaScript
71 lines
2.0 KiB
JavaScript
// MusicRoom - Init module
|
|
// Application initialization sequence
|
|
|
|
(function() {
|
|
const M = window.MusicRoom;
|
|
|
|
// Fetch server status/config
|
|
async function loadServerStatus() {
|
|
try {
|
|
const res = await fetch("/api/status");
|
|
M.serverStatus = await res.json();
|
|
console.log("Server status:", M.serverStatus);
|
|
} catch (e) {
|
|
console.warn("Failed to load server status");
|
|
M.serverStatus = null;
|
|
}
|
|
}
|
|
|
|
// Initialize track storage
|
|
async function initStorage() {
|
|
await TrackStorage.init();
|
|
await M.updateCacheStatus();
|
|
console.log(`TrackStorage: ${M.cachedTracks.size} tracks cached`);
|
|
}
|
|
|
|
// Setup panel tab switching
|
|
function initPanelTabs() {
|
|
const tabs = document.querySelectorAll(".panel-tab");
|
|
tabs.forEach(tab => {
|
|
tab.onclick = () => {
|
|
const tabId = tab.dataset.tab;
|
|
const panel = tab.closest("#library-panel, #queue-panel");
|
|
if (!panel) return;
|
|
|
|
// Update active tab
|
|
panel.querySelectorAll(".panel-tab").forEach(t => t.classList.remove("active"));
|
|
tab.classList.add("active");
|
|
|
|
// Update active view
|
|
panel.querySelectorAll(".panel-view").forEach(v => v.classList.remove("active"));
|
|
const view = panel.querySelector(`#${tabId}-view`);
|
|
if (view) view.classList.add("active");
|
|
};
|
|
});
|
|
}
|
|
|
|
// Setup history panel handlers
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
const btnHistory = M.$("#btn-history");
|
|
const btnClose = M.$("#btn-close-history");
|
|
|
|
if (btnHistory) {
|
|
btnHistory.onclick = () => M.toggleToastHistory();
|
|
}
|
|
if (btnClose) {
|
|
btnClose.onclick = () => M.toggleToastHistory();
|
|
}
|
|
|
|
initPanelTabs();
|
|
});
|
|
|
|
// Initialize the application
|
|
Promise.all([initStorage(), loadServerStatus()]).then(async () => {
|
|
await M.loadLibrary();
|
|
await M.loadCurrentUser();
|
|
if (M.currentUser) {
|
|
M.loadChannels();
|
|
}
|
|
});
|
|
})();
|