New useContent composable to store global navigation state. Fixes for Markdown and Canvas

This commit is contained in:
2024-12-30 20:46:24 +01:00
parent 031a51c2fe
commit 9515132659
31 changed files with 320 additions and 220 deletions

View File

@@ -89,10 +89,10 @@
<script setup lang="ts">
import { Icon } from '@iconify/vue/dist/iconify.js';
import type { NavigationTreeItem } from '~/server/api/navigation.get';
import { iconByType } from '#shared/general.utils';
import type { DropdownOption } from '~/components/base/DropdownMenu.vue';
import { hasPermissions } from '~/shared/auth.util';
import type { TreeItem } from '~/types/content';
const options = ref<DropdownOption[]>([{
type: 'item',
@@ -114,13 +114,10 @@ watch(route, () => {
open.value = false;
});
const { data: pages } = await useLazyFetch('/api/navigation', {
transform: transform,
watch: [useRouter().currentRoute]
});
function transform(list: NavigationTreeItem[] | undefined): NavigationTreeItem[] | undefined
const { tree } = useContent();
const pages = computed(() => transform(tree.value));
function transform(list: TreeItem[] | undefined): TreeItem[] | undefined
{
return list?.map(e => ({ ...e, open: path.value?.startsWith(e.path), children: transform(e.children) }));
return list?.filter(e => e.navigable)?.map(e => ({ ...e, open: path.value?.startsWith(e.path), children: transform(e.children) }));
}
</script>