mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-09 20:12:14 +10:00
* feat: small refactor * fix: appimage build script * fix: add NO_STRIP to AppImage build * fix: build and dev mode from refactor * fix: submodule step 1 * fix: submodules step 2
33 lines
929 B
TypeScript
33 lines
929 B
TypeScript
import type { RouteLocationNormalized } from "vue-router";
|
|
import type { NavigationItem } from "~/types";
|
|
|
|
export const useCurrentNavigationIndex = (
|
|
navigation: Array<NavigationItem>
|
|
) => {
|
|
const router = useRouter();
|
|
const route = useRoute();
|
|
|
|
const currentNavigation = ref(-1);
|
|
|
|
function calculateCurrentNavIndex(to: RouteLocationNormalized) {
|
|
const validOptions = navigation
|
|
.map((e, i) => ({ ...e, index: i }))
|
|
.filter((e) => to.fullPath.startsWith(e.prefix));
|
|
const bestOption = validOptions
|
|
.sort((a, b) => b.route.length - a.route.length)
|
|
.at(0);
|
|
|
|
return bestOption?.index ?? -1;
|
|
}
|
|
|
|
currentNavigation.value = calculateCurrentNavIndex(route);
|
|
|
|
router.afterEach((to) => {
|
|
currentNavigation.value = calculateCurrentNavIndex(to);
|
|
});
|
|
|
|
return {currentNavigation, recalculateNavigation: () => {
|
|
currentNavigation.value = calculateCurrentNavIndex(route);
|
|
}};
|
|
};
|