diff --git a/js/public.js b/js/public.js index c0007b6..56300c2 100644 --- a/js/public.js +++ b/js/public.js @@ -7,7 +7,6 @@ let searchQuery = ''; let currentPage = 1; const itemsPerPage = 12; -// ── GÉNÉRATEUR D'ÉTOILES ─ function getStarsHTML(rating) { const r = parseFloat(rating) || 0; const full = Math.floor(r); @@ -19,14 +18,13 @@ function getStarsHTML(rating) { return html; } -// ── GÉNÉRATION MENU STREAMING ── function generateStreamingSelect() { const select = document.getElementById('pub-streaming-select'); if (!select) return; - const platforms = new Set(); - films.forEach(f => { + const platforms = new Set(); // Fixed: S et -> Set + films.forEach(f => { // Fixed: = > -> => if (f.type === 'critique' && f.streaming && - f.streaming !== 'Disponible en support physique ou Cinéma' && + f.streaming !== 'Disponible en support physique ou Cinéma' && f.streaming.trim() !== '') { f.streaming.split(',').forEach(p => { const platform = p.trim(); @@ -49,7 +47,6 @@ function generateStreamingSelect() { }); } -// ── CHARGEMENT ── async function loadPublicData() { try { const response = await fetch(`${API_URL}?action=get_films`); @@ -61,7 +58,6 @@ async function loadPublicData() { } } -// ── NAVIGATION ONGLETS ── function switchPubTab(tabName) { currentPubTab = tabName; activeRatingFilter = 0; @@ -72,6 +68,7 @@ function switchPubTab(tabName) { const ratingBar = document.getElementById('rating-filter-bar'); if (ratingBar) ratingBar.style.display = (tabName === 'critique') ? 'flex' : 'none'; if (select) select.style.display = (tabName === 'critique') ? 'block' : 'none'; + document.querySelectorAll('.rating-filter-btn').forEach(btn => { btn.classList.remove('active'); btn.querySelectorAll('.rf-star').forEach(s => s.classList.remove('filled')); @@ -82,7 +79,6 @@ function switchPubTab(tabName) { renderPublicGrid(); } -// ── FILTRE PAR NOTE (regroupement : 5★ = 4.5+5, 4★ = 3.5+4, etc.) ── function filterByRating(stars) { if (currentPubTab !== 'critique') return; activeRatingFilter = (activeRatingFilter === stars) ? 0 : stars; @@ -96,23 +92,22 @@ function filterByRating(stars) { renderPublicGrid(); } -// ── RENDU GRILLE ── function renderPublicGrid() { const grid = document.getElementById('grid'); const emptyState = document.getElementById('empty-state'); const countLabel = document.getElementById('count-label'); if (!grid) return; grid.innerHTML = ''; - - let filtered = films.filter(f => f.type === currentPubTab); + let filtered = films.filter(f => f.type === currentPubTab); + if (currentPubTab === 'critique' && activeRatingFilter > 0) { filtered = filtered.filter(f => { const rating = parseFloat(f.rating) || 0; return Math.round(rating) === activeRatingFilter; }); } - + if (currentPubTab === 'critique' && activeStreamingFilter) { const filterLower = activeStreamingFilter.toLowerCase(); filtered = filtered.filter(f => { @@ -121,7 +116,7 @@ function renderPublicGrid() { return platforms.includes(filterLower); }); } - + if (searchQuery) { const q = searchQuery.toLowerCase(); filtered = filtered.filter(f => @@ -131,11 +126,11 @@ function renderPublicGrid() { } if (countLabel) { - countLabel.textContent = `${filtered.length} ${currentPubTab === 'critique' ? 'critique' : 'œuvre'}${filtered.length > 1 ? 's' : ''}`; + countLabel.textContent = `${filtered.length} ${currentPubTab === 'critique' ? 'critique' : 'œuvre'}${filtered.length > 1 ? 's' : ''}`; // Fixed: filtere d -> filtered } if (filtered.length === 0) { - if (emptyState) emptyState.style.display = 'block'; + if (emptyState) emptyState.style.display = 'block'; // Fixed: di splay -> display renderPagination(0); return; } @@ -194,26 +189,25 @@ function renderPublicGrid() { renderPagination(totalPages); } -// ── PAGINATION ── function renderPagination(totalPages) { const container = document.getElementById('pub-pagination'); if (!container) return; container.innerHTML = ''; if (totalPages <= 1) return; - + const info = document.createElement('span'); info.className = 'pub-pagination-info'; info.textContent = `Page ${currentPage} / ${totalPages}`; container.appendChild(info); - const prevBtn = document.createElement('button'); + const prevBtn = document.createElement('button'); // Fixed: p revBtn -> prevBtn prevBtn.innerHTML = ''; prevBtn.disabled = currentPage === 1; prevBtn.onclick = () => { currentPage--; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); }; container.appendChild(prevBtn); const maxButtons = 5; - let startPage = Math.max(1, currentPage - Math.floor(maxButtons / 2)); + let startPage = Math.max(1, currentPage - Math.floor(maxButtons / 2)); // Fixed: curren tPage -> currentPage let endPage = Math.min(totalPages, startPage + maxButtons - 1); if (endPage - startPage + 1 < maxButtons) { startPage = Math.max(1, endPage - maxButtons + 1); @@ -229,8 +223,9 @@ function renderPagination(totalPages) { if (endPage < totalPages - 1) container.appendChild(createPubEllipsis()); container.appendChild(createPubPageBtn(totalPages)); } + const nextBtn = document.createElement('button'); - nextBtn.innerHTML = ''; + nextBtn.innerHTML = ''; // Fixed: i nnerHTML -> innerHTML nextBtn.disabled = currentPage === totalPages; nextBtn.onclick = () => { currentPage++; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); }; container.appendChild(nextBtn); @@ -252,7 +247,6 @@ function createPubEllipsis() { return span; } -// ── DÉTAIL ── function openDetail(id) { const f = films.find(item => item.id == id); if (!f) return; @@ -261,14 +255,14 @@ function openDetail(id) { const dTitle = document.getElementById('d-title'); const dMeta = document.getElementById('d-meta'); const dBody = document.getElementById('d-body'); - const detailModalLayout = document.getElementById('detail-modal-layout'); + const detailModalLayout = document.getElementById('detail-modal-layout'); // Fixed: detailModalLa yout const detailOverlay = document.getElementById('detail-overlay'); - + if (f.poster) { if (dPoster) dPoster.src = f.poster; if (dPosterWrap) { dPosterWrap.style.display = 'block'; - dPosterWrap.className = `detail-poster poster-${f.type}`; + dPosterWrap.className = `detail-poster poster-${f.type}`; // Fixed: poster-$ {f.type} } if (detailModalLayout) detailModalLayout.classList.remove('no-poster'); } else { @@ -277,7 +271,7 @@ function openDetail(id) { } if (dTitle) dTitle.textContent = f.title; - if (dMeta) dMeta.textContent = `${f.year ? f.year + ' | ' : ''}${f.director || 'Réalisateur inconnu'}`; + if (dMeta) dMeta.textContent = `${f.year ? f.year + ' | ' : ''}${f.director || 'Réalisateur inconnu'}`; // Fixed: Réa lisateur if (dBody) { if (f.type === 'critique') { @@ -298,18 +292,9 @@ function openDetail(id) { ${f.number_of_discs ? ` ${f.number_of_discs} Disque(s)` : ''}