Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Remove multiple monitors at once. #5481

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
  • Loading branch information
homelab-alpha committed Dec 29, 2024
commit 4e8264f6e60110c26aa1a1b3ada21c021cbaf27e
33 changes: 22 additions & 11 deletions src/components/MonitorList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -333,23 +348,19 @@ 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];

// 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));
}
});
});

// Delay for UI updates before reloading the page
setTimeout(() => {
if (!Object.keys(this.selectedMonitors).length) {
window.location.reload(); // Refresh the page to show updates
}
}, 5000);

// Exit selection mode as deletion is in progress
this.cancelSelectMode();
},
Expand Down
Loading