generated from pascalmartineau/wp-skeleton
feat: Initial Nuxt app
This commit is contained in:
14
wp-content/themes/ccat/app/composables/useMenuItems.ts
Normal file
14
wp-content/themes/ccat/app/composables/useMenuItems.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { MenuLocationEnum } from "#graphql-operations";
|
||||
import type { NavigationMenuItem } from "@nuxt/ui";
|
||||
|
||||
export async function useMenuItems(location: MenuLocationEnum) {
|
||||
const { data } = await useAsyncGraphqlQuery("menuItems", { location }, { graphqlCaching: { client: true } });
|
||||
if (data.value?.errors?.length) {
|
||||
throw createError({ statusCode: 500, message: "Erreur lors de la récupération des éléments de menu" });
|
||||
}
|
||||
const menuItems: NavigationMenuItem[] = (data.value?.data.menuItems?.nodes || []).map(({ childItems, ...menuItem }) => ({
|
||||
...menuItem,
|
||||
children: childItems?.nodes || [],
|
||||
}));
|
||||
return { menuItems };
|
||||
}
|
||||
Reference in New Issue
Block a user