72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
import type {
|
|
FooterLinkItem,
|
|
FooterRefDataRaw,
|
|
} from "@/types/components/footer/footer"
|
|
import type { HeaderRefResponse } from "@/types/header"
|
|
import { Edges } from "@/types/requests/utils/edges"
|
|
import { NodeRefs } from "@/types/requests/utils/refs"
|
|
|
|
export function getConnections(refs: HeaderRefResponse) {
|
|
const connections: Edges<NodeRefs>[] = []
|
|
const headerData = refs.all_header.items[0]
|
|
const topLink = headerData.top_link
|
|
if (topLink) {
|
|
connections.push(topLink.linkConnection)
|
|
}
|
|
|
|
headerData.menu_items.forEach(
|
|
({ linkConnection, see_all_link, cardConnection, submenu }) => {
|
|
const card = cardConnection.edges[0]?.node
|
|
connections.push(linkConnection)
|
|
|
|
if (see_all_link) {
|
|
connections.push(see_all_link.linkConnection)
|
|
}
|
|
|
|
if (card) {
|
|
if (card.primary_button) {
|
|
connections.push(card.primary_button.linkConnection)
|
|
}
|
|
if (card.secondary_button) {
|
|
connections.push(card.secondary_button.linkConnection)
|
|
}
|
|
}
|
|
|
|
submenu.forEach(({ links }) => {
|
|
links.forEach(({ linkConnection }) => {
|
|
connections.push(linkConnection)
|
|
})
|
|
})
|
|
}
|
|
)
|
|
|
|
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
|
|
}
|