51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
// App Logic for Control de Gastos
|
|
|
|
// Toast notification system
|
|
function showToast(message, type = 'info') {
|
|
const container = document.getElementById('toast-container');
|
|
if (!container) return;
|
|
|
|
const toast = document.createElement('div');
|
|
toast.className = 'toast';
|
|
|
|
if (type === 'success') {
|
|
toast.style.borderLeftColor = 'var(--accent-secondary)';
|
|
} else if (type === 'danger') {
|
|
toast.style.borderLeftColor = 'var(--danger)';
|
|
}
|
|
|
|
toast.innerHTML = `<div>${message}</div>`;
|
|
container.appendChild(toast);
|
|
|
|
// Trigger animation
|
|
setTimeout(() => {
|
|
toast.classList.add('show');
|
|
}, 10);
|
|
|
|
// Remove toast after 5 seconds
|
|
setTimeout(() => {
|
|
toast.classList.remove('show');
|
|
setTimeout(() => {
|
|
if (container.contains(toast)) {
|
|
container.removeChild(toast);
|
|
}
|
|
}, 300);
|
|
}, 5000);
|
|
}
|
|
|
|
// HTMX HTMX HTMX
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
// Re-initialize Lucide icons when HTMX swaps content
|
|
if (typeof lucide !== 'undefined' && document.body.addEventListener) {
|
|
document.body.addEventListener('htmx:afterSwap', function(evt) {
|
|
lucide.createIcons();
|
|
});
|
|
|
|
document.body.addEventListener('htmx:wsAfterMessage', function(evt) {
|
|
lucide.createIcons();
|
|
// Optional: trigger toast
|
|
showToast('Actualización en tiempo real recibida', 'info');
|
|
});
|
|
}
|
|
});
|