Refined: Improve monitor deletion process and UI update

- Replaced `window.location.reload()` with Vue Router navigation to a temporary route for smoother page reload.
- Added Vue Router redirection to `/dashboard` after monitor deletion for better user experience.
- Updated function documentation to clarify behavior and return type.

modified: src/components/MonitorList.vue
This commit is contained in:
GJS 2024-12-30 06:33:50 +01:00
parent 4e8264f6e6
commit f3948ce802
No known key found for this signature in database
GPG key ID: BE32D9EAF927E85B

View file

@ -342,26 +342,32 @@ export default {
* Delete each selected monitor and update the UI once the deletion is complete.
* This method initiates the deletion process for all selected monitors, updates
* the user interface, and reloads the page to reflect the changes.
* @returns {void}
* @returns {void} - This function does not return any value.
*/
deleteSelected() {
// Delete each selected monitor
// Iterate over each selected monitor's ID and delete it
Object.keys(this.selectedMonitors).forEach(id => {
// Call the root method to delete the monitor by its ID
this.$root.deleteMonitor(id, (res) => {
// If the monitor deletion is successful
if (res.ok) {
// Remove the monitor from the selectedMonitors list upon successful deletion
delete this.selectedMonitors[id];
// Refresh the page immediately after deleting the selected monitors
window.location.reload();
// Use Vue Router to navigate to a temporary route before redirecting to /dashboard
// This reloads the page to reflect changes after deletion
this.$router.push("/temp").then(() => {
this.$router.push("/dashboard");
});
// Store a flag in localStorage to trigger a toast notification once the page reloads
// Store a flag in localStorage to trigger a toast notification on page reload
// This ensures the notification displays after the page refreshes
localStorage.setItem("toastMessage", JSON.stringify(res));
}
});
});
// Exit selection mode as deletion is in progress
// Exit the selection mode, indicating that the deletion process is in progress
this.cancelSelectMode();
},