fix: get locale from page connection

This commit is contained in:
Christel Westerberg
2024-02-12 13:20:32 +01:00
parent 9ed73457f8
commit 1ba9672240
7 changed files with 20 additions and 16 deletions

View File

@@ -67,8 +67,9 @@ function ListItem({ listItem }: { listItem: ListItem }) {
</li>
)
case BlockListItemsEnum.CurrentBlocksPageBlocksListBlockListItemsListItemInternalLink:
const links = listItem.list_item_internal_link.pageConnection.edges
return links.map((link, i) => (
const link = listItem.list_item_internal_link.pageConnection.edges[0]
const linkUrlWithLocale= `/${link.node.system.locale}${link.node.url}`
return (
<li
key={link.node.system.uid}
className={` ${
@@ -79,13 +80,13 @@ function ListItem({ listItem }: { listItem: ListItem }) {
${styles.listItem}
`}
>
<Link href={link.node.url} className={styles.link}>
<Link href={linkUrlWithLocale} className={styles.link}>
{listItem.list_item_internal_link.link_text}
</Link>
<br />
<span>{listItem.list_item_internal_link.subtitle}</span>
</li>
))
)
default:
return null

View File

@@ -1,6 +1,7 @@
fragment CurrentBlocksPageLink on CurrentBlocksPage {
system {
uid
locale
}
title
url
@@ -9,7 +10,8 @@ fragment CurrentBlocksPageLink on CurrentBlocksPage {
fragment TempPageLink on TempPage {
system {
uid
locale
}
title
url
}
}

View File

@@ -1,5 +1,5 @@
import type { Edges } from "../utils/edges"
import type { ExternalLink } from "../utils/externalLink"
import type { TempPageLink } from "../utils/tempPageLink"
import type { PageLink } from "../utils/pageLink"
import { Typename } from "../utils/typename"
@@ -36,7 +36,7 @@ type InternalLinkListItem = Typename<
link_text?: string
list_item_style: ListItemStyle
subtitle?: string
pageConnection: Edges<ExternalLink | PageLink>
pageConnection: Edges<TempPageLink | PageLink>
}
},
BlockListItemsEnum.CurrentBlocksPageBlocksListBlockListItemsListItemInternalLink

View File

@@ -1,8 +1,5 @@
import type { SysAsset } from "./utils/asset"
import type { ExternalLinkType } from "./utils/externalLink"
import type { TempPageLinkType } from "./utils/tempPageLink"
import type { PageLinkType } from "./utils/pageLink"
export type Embeds =
| ExternalLinkType
| PageLinkType
| SysAsset
export type Embeds = TempPageLinkType | PageLinkType | SysAsset

View File

@@ -1,7 +1,7 @@
import type { Image } from "../image"
import type { Edges } from "./utils/edges"
import type { Embeds } from "./embeds"
import type { ExternalLink } from "./utils/externalLink"
import type { TempPageLink } from "./utils/tempPageLink"
import type { PageLink } from "./utils/pageLink"
import type { RTEDocument } from "../rte/node"
@@ -13,7 +13,7 @@ export type Puff = {
title: string
}
link_text?: string
pageConnection: Edges<ExternalLink | PageLink>
pageConnection: Edges<TempPageLink | PageLink>
system: {
uid: string
}

View File

@@ -1,9 +1,11 @@
import { Lang } from "@/types/lang"
import type { EmbedEnum } from "./embeds"
import type { Typename } from "./typename"
export type PageLink = {
system: {
uid: string
locale: Lang
}
title: string
url: string

View File

@@ -1,12 +1,14 @@
import { Lang } from "@/types/lang"
import type { EmbedEnum } from "./embeds"
import type { Typename } from "./typename"
export type ExternalLink = {
export type TempPageLink = {
system: {
uid: string
locale: Lang
}
title: string
url: string
}
export type ExternalLinkType = Typename<ExternalLink, EmbedEnum.TempPage>
export type TempPageLinkType = Typename<TempPageLink, EmbedEnum.TempPage>