Add toast deduplication and enhance provider test status notifications

This commit is contained in:
StarFleetCPTN
2025-04-19 17:03:33 -07:00
parent 4b5929331f
commit 7ba40483e0
3 changed files with 47 additions and 7 deletions
+21
View File
@@ -3,7 +3,28 @@ package toast
templ ShowToastJS() {
<script>
// Notification system
// Global tracking of shown messages to prevent duplicates
window.shownToastMessages = window.shownToastMessages || [];
function showToast(message, type) {
// Check if this exact message has been shown in the last 500ms
const messageKey = `${message}-${type}`;
if (window.shownToastMessages.includes(messageKey)) {
console.log(`Preventing duplicate toast: ${messageKey}`);
return;
}
// Add to shown messages
window.shownToastMessages.push(messageKey);
// Remove from tracking after 500ms to allow the same message later if needed
setTimeout(() => {
const index = window.shownToastMessages.indexOf(messageKey);
if (index > -1) {
window.shownToastMessages.splice(index, 1);
}
}, 500);
const toastContainer = document.getElementById('toast-container');
if (!toastContainer) {
console.error("Toast container not found!");
+25 -7
View File
@@ -212,15 +212,33 @@ templ StorageProviders(ctx context.Context, data StorageProvidersData) {
localStorage.removeItem('showProviderDuplicateToast');
}
// Keep other status-based toasts if needed
// Process URL parameters for toast notifications
const urlParams = new URLSearchParams(window.location.search);
// Handle combined status and test_status parameters
if (urlParams.get('status') === 'created') {
showToast('Provider created successfully', 'success');
}
if (urlParams.get('status') === 'updated') {
showToast('Provider updated successfully', 'success');
}
if (urlParams.get('error')) {
const testStatus = urlParams.get('test_status');
const errorMsg = urlParams.get('error');
if (testStatus === 'success') {
showToast('Provider created and tested successfully', 'success');
} else if (testStatus === 'failed' && errorMsg) {
showToast(`Provider created but test failed: ${errorMsg}`, 'error');
} else {
showToast('Provider created successfully', 'success');
}
} else if (urlParams.get('status') === 'updated') {
const testStatus = urlParams.get('test_status');
const errorMsg = urlParams.get('error');
if (testStatus === 'success') {
showToast('Provider updated and tested successfully', 'success');
} else if (testStatus === 'failed' && errorMsg) {
showToast(`Provider updated but test failed: ${errorMsg}`, 'error');
} else {
showToast('Provider updated successfully', 'success');
}
} else if (urlParams.get('error')) {
showToast(urlParams.get('error'), 'error');
}
});
+1
View File
@@ -1,4 +1,5 @@
document.addEventListener('DOMContentLoaded', () => {
// Show test modal when the test button is clicked
document.querySelectorAll('.test-provider-btn').forEach(button => {
button.addEventListener('click', async (e) => {