77 lines
1.9 KiB
JavaScript
77 lines
1.9 KiB
JavaScript
// ===============================
|
|
// AVVIO
|
|
// ===============================
|
|
console.log("main.js avviato");
|
|
|
|
// Carica le foto iniziali
|
|
loadPhotos();
|
|
|
|
// ===============================
|
|
// VARIABILI GLOBALI PER LE OPZIONI
|
|
// ===============================
|
|
let currentSort = "desc"; // "desc" = più recenti prima
|
|
let currentGroup = "auto"; // auto = Oggi, Ieri, Settimana...
|
|
let currentFilter = null; // folder / location / type
|
|
|
|
// ===============================
|
|
// APERTURA / CHIUSURA OPTIONS SHEET
|
|
// ===============================
|
|
const optionsBtn = document.getElementById("optionsBtn");
|
|
const optionsSheet = document.getElementById("optionsSheet");
|
|
|
|
optionsBtn.addEventListener("click", () => {
|
|
optionsSheet.classList.add("open");
|
|
});
|
|
|
|
function closeOptionsSheet() {
|
|
optionsSheet.classList.remove("open");
|
|
}
|
|
|
|
// Chiudi se clicchi fuori
|
|
optionsSheet.addEventListener("click", (e) => {
|
|
if (e.target === optionsSheet) closeOptionsSheet();
|
|
});
|
|
|
|
// ===============================
|
|
// GESTIONE PULSANTI DEL BOTTOM SHEET OPZIONI
|
|
// ===============================
|
|
document.querySelectorAll("#optionsSheet .sheet-btn").forEach(btn => {
|
|
btn.addEventListener("click", () => {
|
|
|
|
if (btn.dataset.sort) {
|
|
currentSort = btn.dataset.sort;
|
|
}
|
|
|
|
if (btn.dataset.group) {
|
|
currentGroup = btn.dataset.group;
|
|
}
|
|
|
|
if (btn.dataset.filter) {
|
|
currentFilter = btn.dataset.filter;
|
|
}
|
|
|
|
closeOptionsSheet();
|
|
refreshGallery();
|
|
});
|
|
});
|
|
|
|
// ===============================
|
|
// FUNZIONE CENTRALE DI AGGIORNAMENTO GALLERIA
|
|
// ===============================
|
|
function refreshGallery() {
|
|
console.log("Aggiornamento galleria...");
|
|
|
|
let photos = [...photosData];
|
|
|
|
// 1) Filtri
|
|
photos = applyFilters(photos);
|
|
|
|
// 2) Ordinamento
|
|
photos = sortByDate(photos, currentSort);
|
|
|
|
// 3) Raggruppamento
|
|
const sections = groupByDate(photos, currentGroup);
|
|
|
|
// 4) Rendering
|
|
renderGallery(sections);
|
|
}
|