89 lines
2.7 KiB
TypeScript
89 lines
2.7 KiB
TypeScript
import type { z } from "zod"
|
|
|
|
import type { AssetSystem, System } from "../schemas/system"
|
|
import type { startPageRefsSchema } from "./output"
|
|
|
|
export namespace StartPageEnum {
|
|
export namespace ContentStack {
|
|
export const enum blocks {
|
|
CardsGrid = "StartPageBlocksCardsGrid",
|
|
CarouselCards = "StartPageBlocksCarouselCards",
|
|
FullWidthCampaign = "StartPageBlocksFullWidthCampaign",
|
|
JoinScandicFriends = "StartPageBlocksJoinScandicFriends",
|
|
VideoCard = "StartPageBlocksVideoCard",
|
|
}
|
|
}
|
|
}
|
|
|
|
export interface StartPageRefs extends z.output<typeof startPageRefsSchema> {}
|
|
|
|
export function getConnectionsFromAssets({ start_page }: StartPageRefs) {
|
|
const connections: AssetSystem["system"][] = []
|
|
|
|
if (start_page.blocks) {
|
|
start_page.blocks.forEach((block) => {
|
|
switch (block.__typename) {
|
|
case StartPageEnum.ContentStack.blocks.VideoCard:
|
|
if (block.video_card?.video.sourceConnection.edges[0]) {
|
|
connections.push(
|
|
block.video_card.video.sourceConnection.edges[0].node.system
|
|
)
|
|
}
|
|
break
|
|
default:
|
|
break
|
|
}
|
|
})
|
|
}
|
|
return connections
|
|
}
|
|
|
|
export function getConnections({ start_page }: StartPageRefs) {
|
|
const connections: System["system"][] = [start_page.system]
|
|
|
|
if (start_page.blocks) {
|
|
start_page.blocks.forEach((block) => {
|
|
const typeName = block.__typename
|
|
switch (typeName) {
|
|
case StartPageEnum.ContentStack.blocks.FullWidthCampaign:
|
|
block.full_width_campaign.full_width_campaignConnection.edges.forEach(
|
|
({ node }) => {
|
|
if (node.system) {
|
|
connections.push(node.system)
|
|
}
|
|
}
|
|
)
|
|
break
|
|
case StartPageEnum.ContentStack.blocks.CardsGrid:
|
|
block.cards_grid.forEach((card) => {
|
|
connections.push(card)
|
|
})
|
|
break
|
|
case StartPageEnum.ContentStack.blocks.CarouselCards:
|
|
block.carousel_cards.card_groups.forEach((group) => {
|
|
group.cardConnection.edges.forEach((node) => {
|
|
connections.push(node.node.system)
|
|
})
|
|
})
|
|
break
|
|
case StartPageEnum.ContentStack.blocks.JoinScandicFriends:
|
|
if (block.join_scandic_friends.primary_button) {
|
|
connections.push(block.join_scandic_friends.primary_button)
|
|
}
|
|
break
|
|
case StartPageEnum.ContentStack.blocks.VideoCard: {
|
|
if (block.video_card?.system) {
|
|
connections.push(block.video_card.system)
|
|
}
|
|
break
|
|
}
|
|
default:
|
|
const _exhaustiveCheck: never = typeName
|
|
break
|
|
}
|
|
})
|
|
}
|
|
|
|
return connections
|
|
}
|