From 9b45a9d0504e4fa842ee87c798d0ac547280c177 Mon Sep 17 00:00:00 2001 From: Raul Victor Trombin Date: Thu, 13 Feb 2025 15:12:00 -0300 Subject: [PATCH] ping-viewer-next-frontend: App: Add useMenuCoordination composable --- .../src/composables/useMenuCoordination.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ping-viewer-next-frontend/src/composables/useMenuCoordination.js diff --git a/ping-viewer-next-frontend/src/composables/useMenuCoordination.js b/ping-viewer-next-frontend/src/composables/useMenuCoordination.js new file mode 100644 index 00000000..4da3f2a8 --- /dev/null +++ b/ping-viewer-next-frontend/src/composables/useMenuCoordination.js @@ -0,0 +1,28 @@ +import { watch } from 'vue'; + +export function useMenuCoordination(menus, options = {}) { + const { allowTransitions = [] } = options; + + for (const [currentMenu, currentRef] of Object.entries(menus)) { + watch(currentRef, (newValue) => { + if (newValue) { + const lastOpenMenu = Object.entries(menus).find( + ([_, ref]) => ref.value && ref !== currentRef + )?.[0]; + + for (const [otherMenu, otherRef] of Object.entries(menus)) { + if (otherMenu !== currentMenu) { + const shouldAllowTransition = allowTransitions.some( + (transition) => + transition.from === lastOpenMenu && transition.to.includes(currentMenu) + ); + + if (!shouldAllowTransition) { + otherRef.value = false; + } + } + } + } + }); + } +}