Spaces:
Running
Running
File size: 5,322 Bytes
fb99799 d7a4583 055e879 d7a4583 055e879 d7a4583 14cf53f 535a5e2 14cf53f fb99799 8931644 055e879 6ca953f fb99799 8931644 fb99799 6ca953f 8931644 fb99799 6ca953f 055e879 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
// 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();
});
|