Skip to content

Commit

Permalink
ping-viewer-next-frontend: App: Add useMenuCoordination composable
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulTrombin committed Feb 13, 2025
1 parent 6f537d5 commit 9b45a9d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ping-viewer-next-frontend/src/composables/useMenuCoordination.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
});
}
}

0 comments on commit 9b45a9d

Please sign in to comment.