fix: refine url logic based on typename
This commit is contained in:
@@ -11,6 +11,8 @@ import {
|
||||
GetNavigationMyPagesData,
|
||||
NavigationItem,
|
||||
MenuItem,
|
||||
PageLink,
|
||||
PageLinkEnum,
|
||||
} from "@/types/requests/myPages/navigation"
|
||||
import { GetNavigationMyPages } from "@/lib/graphql/Query/NavigationMyPages.graphql"
|
||||
|
||||
@@ -26,16 +28,26 @@ export default async function MyPagesLayout({
|
||||
)
|
||||
|
||||
function mapMenuItems(navigationItems: NavigationItem[]) {
|
||||
function getURL(node: PageLink) {
|
||||
switch (node.__typename) {
|
||||
case PageLinkEnum.ContentPage:
|
||||
return node.web.url
|
||||
case PageLinkEnum.CodeDefinedPage:
|
||||
return node.url
|
||||
}
|
||||
}
|
||||
|
||||
return navigationItems.map(({ item }): MenuItem => {
|
||||
const { node } = item.pageConnection.edges[0]
|
||||
const {
|
||||
title,
|
||||
url,
|
||||
system: { uid },
|
||||
} = item.pageConnection.edges[0].node
|
||||
} = node
|
||||
|
||||
return {
|
||||
title,
|
||||
uid,
|
||||
url,
|
||||
url: getURL(node),
|
||||
linkText: item.link_text,
|
||||
subItems: item.sub_items ? mapMenuItems(item.sub_items) : null,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user