feat(SW-186): Added refs and some extra querys

This commit is contained in:
Erik Tiekstra
2024-09-05 09:25:21 +02:00
parent 52fdc1daac
commit 55fdbc527b
11 changed files with 388 additions and 303 deletions

View File

@@ -0,0 +1,40 @@
import { 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
}