Actualiser js/public.js

This commit is contained in:
2026-06-22 16:12:39 +02:00
parent 2025c4c9ae
commit 5f7028d068
+22 -15
View File
@@ -1,12 +1,11 @@
let films = [];
const API_URL = '../api.php'; const API_URL = '../api.php';
let films = [];
let currentPubTab = 'critique'; let currentPubTab = 'critique';
let activeRatingFilter = 0; let activeRatingFilter = 0;
let activeStreamingFilter = ''; let activeStreamingFilter = '';
let searchQuery = ''; let searchQuery = '';
let currentPage = 1; let currentPage = 1;
const itemsPerPage = 12; const itemsPerPage = 12;
let physicalOnlyFilter = false;
function getStarsHTML(rating) { function getStarsHTML(rating) {
const r = parseFloat(rating) || 0; const r = parseFloat(rating) || 0;
@@ -22,8 +21,8 @@ function getStarsHTML(rating) {
function generateStreamingSelect() { function generateStreamingSelect() {
const select = document.getElementById('pub-streaming-select'); const select = document.getElementById('pub-streaming-select');
if (!select) return; if (!select) return;
const platforms = new Set(); // Fixed: S et -> Set const platforms = new Set();
films.forEach(f => { // Fixed: = > -> => films.forEach(f => {
if (f.type === 'critique' && f.streaming && 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.trim() !== '') {
@@ -57,8 +56,7 @@ async function loadPublicData() {
// Écouteur pour le filtre physique // Écouteur pour le filtre physique
const physicalCheckbox = document.getElementById('physical-only-checkbox'); const physicalCheckbox = document.getElementById('physical-only-checkbox');
if (physicalCheckbox) { if (physicalCheckbox) {
physicalCheckbox.addEventListener('change', (e) => { physicalCheckbox.addEventListener('change', () => {
physicalOnlyFilter = e.target.checked;
currentPage = 1; currentPage = 1;
renderPublicGrid(); renderPublicGrid();
}); });
@@ -81,6 +79,12 @@ function switchPubTab(tabName) {
if (ratingBar) ratingBar.style.display = (tabName === 'critique') ? 'flex' : 'none'; if (ratingBar) ratingBar.style.display = (tabName === 'critique') ? 'flex' : 'none';
if (select) select.style.display = (tabName === 'critique') ? 'block' : 'none'; if (select) select.style.display = (tabName === 'critique') ? 'block' : 'none';
// 🔥 Cacher la case physique en mode vidéothèque
const physicalBox = document.querySelector('.physical-filter-box');
if (physicalBox) {
physicalBox.style.display = (tabName === 'critique') ? 'block' : 'none';
}
document.querySelectorAll('.rating-filter-btn').forEach(btn => { document.querySelectorAll('.rating-filter-btn').forEach(btn => {
btn.classList.remove('active'); btn.classList.remove('active');
btn.querySelectorAll('.rf-star').forEach(s => s.classList.remove('filled')); btn.querySelectorAll('.rf-star').forEach(s => s.classList.remove('filled'));
@@ -113,13 +117,16 @@ function renderPublicGrid() {
let filtered = films.filter(f => f.type === currentPubTab); let filtered = films.filter(f => f.type === currentPubTab);
// FILTRE PHYSIQUE UNIQUENENT // 🔥 FILTRE PHYSIQUE UNIQUEMENT (CORRIGÉ)
const physicalFilter = document.getElementById('physical-only-checkbox');
if (physicalFilter && physicalFilter.checked) { if (physicalFilter && physicalFilter.checked) {
filtered = filtered.filter(f => { filtered = filtered.filter(f => {
// Pour les critiques : vérifier le champ streaming // Pour les critiques : vérifier le champ streaming
if (f.type === 'critique') { if (f.type === 'critique') {
return f.streaming && f.streaming.toLowerCase().includes('support physique'); return f.streaming && f.streaming.toLowerCase().includes('support physique');
} }
// Pour la vidéothèque : tout est physique par défaut
return true;
}); });
} }
@@ -148,11 +155,11 @@ function renderPublicGrid() {
} }
if (countLabel) { if (countLabel) {
countLabel.textContent = `${filtered.length} ${currentPubTab === 'critique' ? 'critique' : 'œuvre'}${filtered.length > 1 ? 's' : ''}`; // Fixed: filtere d -> filtered countLabel.textContent = `${filtered.length} ${currentPubTab === 'critique' ? 'critique' : 'œuvre'}${filtered.length > 1 ? 's' : ''}`;
} }
if (filtered.length === 0) { if (filtered.length === 0) {
if (emptyState) emptyState.style.display = 'block'; // Fixed: di splay -> display if (emptyState) emptyState.style.display = 'block';
renderPagination(0); renderPagination(0);
return; return;
} }
@@ -212,14 +219,14 @@ function renderPagination(totalPages) {
info.textContent = `Page ${currentPage} / ${totalPages}`; info.textContent = `Page ${currentPage} / ${totalPages}`;
container.appendChild(info); container.appendChild(info);
const prevBtn = document.createElement('button'); // Fixed: p revBtn -> prevBtn const prevBtn = document.createElement('button');
prevBtn.innerHTML = '<i class="ti ti-chevron-left"></i>'; prevBtn.innerHTML = '<i class="ti ti-chevron-left"></i>';
prevBtn.disabled = currentPage === 1; prevBtn.disabled = currentPage === 1;
prevBtn.onclick = () => { currentPage--; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); }; prevBtn.onclick = () => { currentPage--; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); };
container.appendChild(prevBtn); container.appendChild(prevBtn);
const maxButtons = 5; const maxButtons = 5;
let startPage = Math.max(1, currentPage - Math.floor(maxButtons / 2)); // Fixed: curren tPage -> currentPage let startPage = Math.max(1, currentPage - Math.floor(maxButtons / 2));
let endPage = Math.min(totalPages, startPage + maxButtons - 1); let endPage = Math.min(totalPages, startPage + maxButtons - 1);
if (endPage - startPage + 1 < maxButtons) { if (endPage - startPage + 1 < maxButtons) {
startPage = Math.max(1, endPage - maxButtons + 1); startPage = Math.max(1, endPage - maxButtons + 1);
@@ -237,7 +244,7 @@ function renderPagination(totalPages) {
} }
const nextBtn = document.createElement('button'); const nextBtn = document.createElement('button');
nextBtn.innerHTML = '<i class="ti ti-chevron-right"></i>'; // Fixed: i nnerHTML -> innerHTML nextBtn.innerHTML = '<i class="ti ti-chevron-right"></i>';
nextBtn.disabled = currentPage === totalPages; nextBtn.disabled = currentPage === totalPages;
nextBtn.onclick = () => { currentPage++; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); }; nextBtn.onclick = () => { currentPage++; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); };
container.appendChild(nextBtn); container.appendChild(nextBtn);
@@ -267,14 +274,14 @@ function openDetail(id) {
const dTitle = document.getElementById('d-title'); const dTitle = document.getElementById('d-title');
const dMeta = document.getElementById('d-meta'); const dMeta = document.getElementById('d-meta');
const dBody = document.getElementById('d-body'); const dBody = document.getElementById('d-body');
const detailModalLayout = document.getElementById('detail-modal-layout'); // Fixed: detailModalLa yout const detailModalLayout = document.getElementById('detail-modal-layout');
const detailOverlay = document.getElementById('detail-overlay'); const detailOverlay = document.getElementById('detail-overlay');
if (f.poster) { if (f.poster) {
if (dPoster) dPoster.src = f.poster; if (dPoster) dPoster.src = f.poster;
if (dPosterWrap) { if (dPosterWrap) {
dPosterWrap.style.display = 'block'; dPosterWrap.style.display = 'block';
dPosterWrap.className = `detail-poster poster-${f.type}`; // Fixed: poster-$ {f.type} dPosterWrap.className = `detail-poster poster-${f.type}`;
} }
if (detailModalLayout) detailModalLayout.classList.remove('no-poster'); if (detailModalLayout) detailModalLayout.classList.remove('no-poster');
} else { } else {
@@ -283,7 +290,7 @@ function openDetail(id) {
} }
if (dTitle) dTitle.textContent = f.title; if (dTitle) dTitle.textContent = f.title;
if (dMeta) dMeta.textContent = `${f.year ? f.year + ' | ' : ''}${f.director || 'Réalisateur inconnu'}`; // Fixed: Réa lisateur if (dMeta) dMeta.textContent = `${f.year ? f.year + ' | ' : ''}${f.director || 'Réalisateur inconnu'}`;
if (dBody) { if (dBody) {
if (f.type === 'critique') { if (f.type === 'critique') {