mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-02-07 04:03:51 +00:00
Updated: Improve monitor deletion flow with toast notification
- Added functionality to retrieve and display a toast message from localStorage after the page reloads, triggered by a successful monitor deletion. - Modified the `deleteSelected` method to immediately refresh the page after deleting selected monitors and store the response for the toast notification. - Cleaned up localStorage after showing the toast to avoid repeating the message. modified: src/components/MonitorList.vue
This commit is contained in:
parent
4aa76f50cc
commit
4e8264f6e6
1 changed files with 22 additions and 11 deletions
|
@ -211,6 +211,21 @@ export default {
|
|||
},
|
||||
mounted() {
|
||||
window.addEventListener("scroll", this.onScroll);
|
||||
|
||||
// Retrieve the toast message from localStorage
|
||||
const toastMessage = localStorage.getItem("toastMessage");
|
||||
|
||||
if (toastMessage) {
|
||||
/**
|
||||
* If a toast message exists in localStorage:
|
||||
* 1. Parse the message from string to object format.
|
||||
* 2. Display the toast notification using the root component's toastRes method.
|
||||
* 3. Remove the message from localStorage to prevent it from showing again.
|
||||
*/
|
||||
this.$root.toastRes(JSON.parse(toastMessage)); // Show the toast message
|
||||
localStorage.removeItem("toastMessage"); // Clean up the localStorage
|
||||
}
|
||||
|
||||
},
|
||||
beforeUnmount() {
|
||||
window.removeEventListener("scroll", this.onScroll);
|
||||
|
@ -333,22 +348,18 @@ export default {
|
|||
// Delete each selected monitor
|
||||
Object.keys(this.selectedMonitors).forEach(id => {
|
||||
this.$root.deleteMonitor(id, (res) => {
|
||||
// Display a response message for the operation
|
||||
this.$root.toastRes(res);
|
||||
|
||||
// Remove the monitor from the selection if deletion is successful
|
||||
if (res.ok) {
|
||||
// Remove the monitor from the selectedMonitors list upon successful deletion
|
||||
delete this.selectedMonitors[id];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Delay for UI updates before reloading the page
|
||||
setTimeout(() => {
|
||||
if (!Object.keys(this.selectedMonitors).length) {
|
||||
window.location.reload(); // Refresh the page to show updates
|
||||
// Refresh the page immediately after deleting the selected monitors
|
||||
window.location.reload();
|
||||
|
||||
// Store a flag in localStorage to trigger a toast notification once the page reloads
|
||||
localStorage.setItem("toastMessage", JSON.stringify(res));
|
||||
}
|
||||
}, 5000);
|
||||
});
|
||||
});
|
||||
|
||||
// Exit selection mode as deletion is in progress
|
||||
this.cancelSelectMode();
|
||||
|
|
Loading…
Add table
Reference in a new issue