Spaces:
Running
Running
| // Authentication functions | |
| function isAdminLoggedIn() { | |
| return sessionStorage.getItem('adminToken') !== null; | |
| } | |
| function isUserLoggedIn() { | |
| return sessionStorage.getItem('userToken') !== null; | |
| } | |
| function requireAdminAuth() { | |
| if (!isAdminLoggedIn()) { | |
| window.location.href = 'admin-login.html'; | |
| return false; | |
| } | |
| return true; | |
| } | |
| function requireUserAuth() { | |
| if (!isUserLoggedIn()) { | |
| window.location.href = 'signup.html'; | |
| return false; | |
| } | |
| return true; | |
| } | |
| // Generate QR code for 2FA | |
| function generateQRCode(secret, label) { | |
| const qrUrl = `otpauth://totp/${encodeURIComponent(label)}?secret=${secret}&issuer=Fuse%20Cafe`; | |
| const qrCode = new QRCode(document.createElement('div'), { | |
| text: qrUrl, | |
| width: 128, | |
| height: 128, | |
| colorDark: "#5a3c2b", | |
| colorLight: "#ffffff", | |
| correctLevel: QRCode.CorrectLevel.H | |
| }); | |
| return qrCode._el.firstChild; | |
| } | |
| // Include libraries | |
| const QRCode = typeof window !== 'undefined' ? window.QRCode : require('qrcode'); | |
| // Initialize EmailJS | |
| (function() { | |
| emailjs.init("YOUR_EMAILJS_USER_ID"); // You'll need to get this from EmailJS | |
| })(); | |
| // Main application logic | |
| document.addEventListener('DOMContentLoaded', () => { | |
| console.log('Fuse Cafe is ready!'); | |
| feather.replace(); | |
| // Sidebar minimize functionality | |
| const sidebar = document.querySelector('custom-sidebar'); | |
| const minimizeBtn = document.getElementById('sidebar-minimize'); | |
| if (minimizeBtn) { | |
| minimizeBtn.addEventListener('click', () => { | |
| sidebar.style.transition = 'all 0.3s ease'; | |
| if (sidebar.style.width === '4rem') { | |
| sidebar.style.width = '16rem'; | |
| minimizeBtn.innerHTML = '<i data-feather="chevron-left"></i>'; | |
| } else { | |
| sidebar.style.width = '4rem'; | |
| minimizeBtn.innerHTML = '<i data-feather="chevron-right"></i>'; | |
| } | |
| feather.replace(); | |
| }); | |
| } | |
| // Form submission handler | |
| const signupForm = document.querySelector('form'); | |
| if (signupForm) { | |
| signupForm.addEventListener('submit', (e) => { | |
| e.preventDefault(); | |
| alert('Account creation request received! We will contact you soon.'); | |
| window.location.href = 'index.html'; | |
| }); | |
| } | |
| // Initialize local storage if not exists | |
| if (!localStorage.getItem('fuseCafeData')) { | |
| localStorage.setItem('fuseCafeData', JSON.stringify({ | |
| memories: [], | |
| announcements: [], | |
| shifts: [], | |
| staff: [], | |
| legal: { | |
| tos: '', | |
| privacy: '' | |
| } | |
| })); | |
| } | |
| }); | |
| // Animation triggers | |
| const animateOnScroll = () => { | |
| const elements = document.querySelectorAll('.animate-on-scroll'); | |
| elements.forEach(el => { | |
| const elementTop = el.getBoundingClientRect().top; | |
| if (elementTop < window.innerHeight - 100) { | |
| el.classList.add('animate__animated', 'animate__fadeInUp'); | |
| } | |
| }); | |
| }; | |
| window.addEventListener('scroll', animateOnScroll); | |
| // Helper function to save data to local storage | |
| function saveFuseCafeData(data) { | |
| localStorage.setItem('fuseCafeData', JSON.stringify(data)); | |
| } | |
| // Helper function to load data from local storage | |
| function loadFuseCafeData() { | |
| return JSON.parse(localStorage.getItem('fuseCafeData')) || { | |
| memories: [], | |
| announcements: [], | |
| shifts: [], | |
| staff: [], | |
| legal: { | |
| tos: '', | |
| privacy: '' | |
| } | |
| }; | |
| } | |
| // Initialize data on page load | |
| function initializePageData() { | |
| const data = loadFuseCafeData(); | |
| // Load memories if on memories page | |
| if (document.getElementById('memories-container') && data.memories.length > 0) { | |
| const container = document.getElementById('memories-container'); | |
| data.memories.forEach(memory => { | |
| const memoryCard = document.createElement('div'); | |
| memoryCard.className = 'bg-white rounded-lg overflow-hidden shadow-md border border-[#e2d5c8]'; | |
| memoryCard.innerHTML = ` | |
| <img src="${memory.image}" alt="Memory" class="w-full h-48 object-cover"> | |
| <div class="p-4"> | |
| <p class="text-[#5a3c2b]">${memory.text || 'No description'}</p> | |
| <div class="mt-3 flex justify-between items-center text-sm text-[#6F4E37]"> | |
| <span>${new Date(memory.date).toLocaleDateString()}</span> | |
| <button class="text-red-500 hover:text-red-700" onclick="this.closest('div').remove()"> | |
| <i data-feather="trash-2"></i> | |
| </button> | |
| </div> | |
| </div> | |
| `; | |
| container.appendChild(memoryCard); | |
| }); | |
| } | |
| // Load other data similarly for other pages... | |
| } | |
| // Call initialize function when DOM is loaded | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Show admin buttons if logged in | |
| if (isAdminLoggedIn()) { | |
| const adminButtons = document.querySelectorAll('[id$="-btn"]'); | |
| adminButtons.forEach(btn => btn.style.display = 'block'); | |
| } | |
| initializePageData(); | |
| }); | |