import { getLibraries, getRecentItems } from '../embyApi.js';
import { connectLobby, joinParty, createParty } from '../party.js';
import { navigate } from '../router.js';
import { tileHtml, wireTileButtons, escapeHtml } from '../tiles.js';
export function renderHome(root) {
root.innerHTML = `
Accueil
Watch parties en cours
`;
// Live, not a one-shot fetch: the list (and each card's host/member count)
// updates the moment anything changes anywhere - see
// server/src/socketHandler.js's "lobby" room. The elapsed-time label is
// the one piece that ticks purely client-side (from createdUtc) - no
// point re-pushing from the server once a second just for a clock.
const lobby = connectLobby((parties) => renderParties(root, parties));
const elapsedTimer = setInterval(() => updateElapsedLabels(root), 1000);
loadRecentSections(root);
// Called by router.js before rendering whatever comes next - stops the
// lobby socket and the ticking clock from running after you've navigated
// away (see docs/architecture.md's memory-leak writeup).
return function cleanup() {
lobby.disconnect();
clearInterval(elapsedTimer);
};
}
function renderParties(root, parties) {
const section = root.querySelector('#partiesSection');
const list = root.querySelector('#partiesCarousel');
if (!section || !list) return; // navigated away mid-flight
if (!parties.length) {
section.hidden = true;
list.innerHTML = '';
return;
}
section.hidden = false;
list.innerHTML = parties.map((p) => `