Bläddra i källkod

refactor: close all modals upon route change

Kristian Vos 2 år sedan
förälder
incheckning
b666264796
2 ändrade filer med 16 tillägg och 3 borttagningar
  1. 5 3
      frontend/src/main.js
  2. 11 0
      frontend/src/store/modules/modalVisibility.js

+ 5 - 3
frontend/src/main.js

@@ -221,9 +221,11 @@ router.beforeEach((to, from, next) => {
 		window.stationInterval = 0;
 	}
 
-	if (to.name === "station") {
-		store.dispatch("modalVisibility/closeModal", "manageStation");
-	}
+	// if (to.name === "station") {
+	// 	store.dispatch("modalVisibility/closeModal", "manageStation");
+	// }
+
+	store.dispatch("modalVisibility/closeAllModals");
 
 	if (ws.socket && to.fullPath !== from.fullPath) {
 		ws.clearCallbacks();

+ 11 - 0
frontend/src/store/modules/modalVisibility.js

@@ -76,6 +76,9 @@ const actions = {
 		}),
 	closeCurrentModal: ({ commit }) => {
 		commit("closeCurrentModal");
+	},
+	closeAllModals: ({ commit }) => {
+		commit("closeAllModals");
 	}
 };
 
@@ -109,6 +112,14 @@ const mutations = {
 		state.activeModals.pop();
 
 		delete state.modals[currentlyActiveModalUuid];
+	},
+	closeAllModals(state) {
+		state.activeModals.forEach(modalUuid => {
+			ws.destroyModalListeners(modalUuid);
+		});
+
+		state.activeModals = [];
+		state.modals = {};
 	}
 };