diff --git a/public/js/utils.js b/public/js/utils.js index 50fbdbc..19634d2 100644 --- a/public/js/utils.js +++ b/public/js/utils.js @@ -6,12 +6,34 @@ export const showLoading = (show) => { loadingSpinner.innerHTML = show ? `
` : ''; }; -export const showMessage = (message, type = 'success') => { - const messageBox = document.getElementById('message-box'); - messageBox.innerHTML = ``; - messageBox.classList.remove('hidden'); -}; +// Keep a reference to the timer so we can reset it if a new message appears +let messageTimer = null; +export const showMessage = (message, type = 'success', duration = 4000) => { // duration is 4 seconds + const messageBox = document.getElementById('message-box'); + + // The HTML for the message itself, using Tailwind classes for styling + messageBox.innerHTML = ` + `; + + messageBox.classList.remove('hidden'); + + // Clear any previous timer that might be running + clearTimeout(messageTimer); + + // Set a new timer to hide the message box after the specified duration + messageTimer = setTimeout(() => { + messageBox.classList.add('hidden'); + }, duration); +}; export const formatDecimal = (ms) => ms ? (ms / 3600000).toFixed(2) : '0.00'; export const formatDateTime = (s) => s ? new Date(s).toLocaleString(undefined, { month: '2-digit', day: '2-digit', year: '2-digit', hour: 'numeric', minute: '2-digit' }) : 'N/A'; diff --git a/public/style/style.css b/public/style/style.css index 9a3f9f5..2dc3f77 100644 --- a/public/style/style.css +++ b/public/style/style.css @@ -44,4 +44,15 @@ body { /* A darker text color for the active tab to make it stand out */ color: #1E40AF; /* Tailwind's blue-800 */ font-weight: 500; +} + +/* Sticky Message Box Styles */ +#message-box { + position: fixed; /* 'Fixes' the element relative to the browser window */ + top: 1rem; /* 1rem (16px) from the top */ + left: 50%; /* Start at 50% from the left */ + transform: translateX(-50%); /* Shift left by half its own width to perfectly center it */ + z-index: 2000; /* Ensures it appears on top of all other content */ + width: 90%; /* Make it 90% of the screen width */ + max-width: 500px; /* But no wider than 500px */ } \ No newline at end of file