mirror of
https://github.com/StarFleetCPTN/GoMFT.git
synced 2026-09-08 15:41:20 +02:00
Add toast deduplication and enhance provider test status notifications
This commit is contained in:
@@ -3,7 +3,28 @@ package toast
|
|||||||
templ ShowToastJS() {
|
templ ShowToastJS() {
|
||||||
<script>
|
<script>
|
||||||
// Notification system
|
// Notification system
|
||||||
|
// Global tracking of shown messages to prevent duplicates
|
||||||
|
window.shownToastMessages = window.shownToastMessages || [];
|
||||||
|
|
||||||
function showToast(message, type) {
|
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');
|
const toastContainer = document.getElementById('toast-container');
|
||||||
if (!toastContainer) {
|
if (!toastContainer) {
|
||||||
console.error("Toast container not found!");
|
console.error("Toast container not found!");
|
||||||
|
|||||||
@@ -212,15 +212,33 @@ templ StorageProviders(ctx context.Context, data StorageProvidersData) {
|
|||||||
localStorage.removeItem('showProviderDuplicateToast');
|
localStorage.removeItem('showProviderDuplicateToast');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep other status-based toasts if needed
|
// Process URL parameters for toast notifications
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
|
// Handle combined status and test_status parameters
|
||||||
if (urlParams.get('status') === 'created') {
|
if (urlParams.get('status') === 'created') {
|
||||||
showToast('Provider created successfully', 'success');
|
const testStatus = urlParams.get('test_status');
|
||||||
}
|
const errorMsg = urlParams.get('error');
|
||||||
if (urlParams.get('status') === 'updated') {
|
|
||||||
showToast('Provider updated successfully', 'success');
|
if (testStatus === 'success') {
|
||||||
}
|
showToast('Provider created and tested successfully', 'success');
|
||||||
if (urlParams.get('error')) {
|
} 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');
|
showToast(urlParams.get('error'), 'error');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
|
||||||
// Show test modal when the test button is clicked
|
// Show test modal when the test button is clicked
|
||||||
document.querySelectorAll('.test-provider-btn').forEach(button => {
|
document.querySelectorAll('.test-provider-btn').forEach(button => {
|
||||||
button.addEventListener('click', async (e) => {
|
button.addEventListener('click', async (e) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user