71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
import type {
|
|
FooterLinkItem,
|
|
FooterRefDataRaw,
|
|
} from "@/types/components/footer/footer"
|
|
import { System } from "@/types/requests/system"
|
|
import { Edges } from "@/types/requests/utils/edges"
|
|
import { NodeRefs } from "@/types/requests/utils/refs"
|
|
import type { HeaderRefs } from "@/types/trpc/routers/contentstack/header"
|
|
|
|
export function getConnections({ header }: HeaderRefs) {
|
|
const connections: System["system"][] = [header.system]
|
|
|
|
if (header.top_link?.link) {
|
|
connections.push(header.top_link.link)
|
|
}
|
|
|
|
if (header.menu_items.length) {
|
|
header.menu_items.forEach((menuItem) => {
|
|
if (menuItem.card) {
|
|
connections.push(...menuItem.card)
|
|
}
|
|
if (menuItem.link) {
|
|
connections.push(menuItem.link)
|
|
}
|
|
if (menuItem.see_all_link?.link) {
|
|
connections.push(menuItem.see_all_link.link)
|
|
}
|
|
if (menuItem.submenu.length) {
|
|
menuItem.submenu.forEach((subMenuItem) => {
|
|
if (subMenuItem.links.length) {
|
|
subMenuItem.links.forEach((link) => {
|
|
if (link?.link) {
|
|
connections.push(link.link)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
return connections
|
|
}
|
|
|
|
export function getFooterConnections(refs: FooterRefDataRaw) {
|
|
const connections: Edges<NodeRefs>[] = []
|
|
const footerData = refs.all_footer.items[0]
|
|
const mainLinks = footerData.main_links
|
|
const secondaryLinks = footerData.secondary_links
|
|
const tertiaryLinks = footerData.tertiary_links
|
|
if (mainLinks) {
|
|
mainLinks.forEach(({ pageConnection }) => {
|
|
connections.push(pageConnection)
|
|
})
|
|
}
|
|
secondaryLinks?.forEach(({ links }) => {
|
|
if (links) {
|
|
links.forEach(({ pageConnection }) => {
|
|
connections.push(pageConnection)
|
|
})
|
|
}
|
|
})
|
|
if (tertiaryLinks) {
|
|
tertiaryLinks.forEach(({ pageConnection }) => {
|
|
connections.push(pageConnection)
|
|
})
|
|
}
|
|
|
|
return connections
|
|
}
|