feat(SW-187): App badges localization

This commit is contained in:
Pontus Dreij
2024-09-04 14:07:57 +02:00
parent 3dabc3bfef
commit a3cb24dfd4
21 changed files with 293 additions and 25 deletions

View File

@@ -253,6 +253,12 @@ export const baseQueryRouter = router({
GetCurrentFooterRef,
{
locale: input.lang,
},
{
cache: "force-cache",
next: {
tags: [generateRefsResponseTag(input.lang, "current_footer")],
},
}
)
// There's currently no error handling/validation for the responseRef, should it be added?
@@ -265,6 +271,9 @@ export const baseQueryRouter = router({
},
})
)
const currentFooterUID =
responseRef.data.all_current_footer.items[0].system.uid
const response = await request<CurrentFooterDataRaw>(
GetCurrentFooter,
{
@@ -272,7 +281,7 @@ export const baseQueryRouter = router({
},
{
next: {
tags: [generateRefsResponseTag(input.lang, "current_footer")],
tags: [generateTag(input.lang, currentFooterUID)],
},
}
)
@@ -331,7 +340,7 @@ export const baseQueryRouter = router({
JSON.stringify({ query: { lang: input.lang } })
)
const responseRef = await request<FooterRefDataRaw>(
GetCurrentFooterRef,
GetFooterRef,
{
locale: input.lang,
},
@@ -342,6 +351,7 @@ export const baseQueryRouter = router({
},
}
)
console.log("responseRef", responseRef)
// There's currently no error handling/validation for the responseRef, should it be added?
getFooterCounter.add(1, { lang: input.lang })
console.info(
@@ -352,7 +362,7 @@ export const baseQueryRouter = router({
},
})
)
const currentFooterUID = responseRef.data.all_footer.items[0].system.uid
const footerUID = responseRef.data.all_footer.items[0].system.uid
const response = await request<FooterDataRaw>(
GetFooter,
{
@@ -361,7 +371,7 @@ export const baseQueryRouter = router({
{
cache: "force-cache",
next: {
tags: [generateTag(input.lang, currentFooterUID)],
tags: [generateTag(input.lang, footerUID)],
},
}
)
@@ -413,17 +423,19 @@ export const baseQueryRouter = router({
const mainLinks = transformPageConnectionLinks(
validatedFooterData.main_links
)
console.log(
"secondary_links ",
validatedFooterData.secondary_links[0].links[0].pageConnection?.edges
)
const secondaryLinks = validatedFooterData.secondary_links.map(
(section) => ({
...section,
title: section.title,
links: transformPageConnectionLinks(section.links),
})
)
console.log(
"secondaryLinks data",
JSON.stringify(secondaryLinks, null, 4)
)
return {
mainLinks: mainLinks,
appDownloads: validatedFooterData.app_downloads,

View File

@@ -1,10 +1,24 @@
import type { FooterLinkItem } from "./output"
export function transformPageConnectionLinks(links: FooterLinkItem[]) {
return links.flatMap((link) =>
link.pageConnection?.edges.map((edge) => ({
title: edge.node.title,
url: edge.node.url,
}))
)
console.log("linksdata", links[0].pageConnection?.edges)
if (!links) return []
return links.flatMap((link) => {
if (link.pageConnection?.edges.length) {
return link.pageConnection.edges.map((edge) => ({
title: edge.node.title || "",
url: edge.node.url || "",
openInNewTab: link.open_in_new_tab,
}))
} else if (link.link) {
return [
{
title: link.link.title,
url: link.link.href,
openInNewTab: link.open_in_new_tab,
},
]
}
return []
})
}