All checks were successful
Build and Push Docker Image / docker (push) Successful in 10s
42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
import { state } from './state.js';
|
|
import { connectWS } from './ws.js';
|
|
import { onMessage } from './handlers.js';
|
|
import { wireUi } from './ui.js';
|
|
import { $nameLobby } from './dom.js';
|
|
|
|
// Fetch and store available playlists
|
|
async function loadPlaylists() {
|
|
try {
|
|
const response = await fetch('/api/playlists');
|
|
const data = await response.json();
|
|
if (data.ok && data.playlists) {
|
|
state.playlists = data.playlists;
|
|
return data.playlists;
|
|
}
|
|
} catch (error) {
|
|
console.error('Failed to load playlists:', error);
|
|
}
|
|
return [];
|
|
}
|
|
|
|
// Initialize UI and open WebSocket connection
|
|
wireUi();
|
|
connectWS(onMessage);
|
|
|
|
// Load playlists on startup
|
|
loadPlaylists();
|
|
|
|
// Restore name/id immediately for initial render smoothness
|
|
(() => {
|
|
try {
|
|
const savedPid = localStorage.getItem('playerId');
|
|
if (savedPid && !state.playerId) {
|
|
state.playerId = savedPid;
|
|
}
|
|
} catch {}
|
|
const saved = localStorage.getItem('playerName');
|
|
if (saved && $nameLobby && $nameLobby.value !== saved) {
|
|
$nameLobby.value = saved;
|
|
}
|
|
})();
|