Merged in fix/startpage-cards (pull request #1994)
fix: display carousel cards without filtering * fix: display carousel cards without filtering Approved-by: Erik Tiekstra
This commit is contained in:
@@ -15,7 +15,7 @@ const commonFields = {
|
|||||||
link: buttonSchema.optional(),
|
link: buttonSchema.optional(),
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
const carouselCardGroupsSchema = z
|
const carouselCardGroupsFilteredSchema = z
|
||||||
.array(
|
.array(
|
||||||
z
|
z
|
||||||
.object({
|
.object({
|
||||||
@@ -29,7 +29,6 @@ const carouselCardGroupsSchema = z
|
|||||||
if (!group.filter_label || !group.cardConnection.edges.length) {
|
if (!group.filter_label || !group.cardConnection.edges.length) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const iconIdentifier = group.filter_identifier ?? "favorite"
|
const iconIdentifier = group.filter_identifier ?? "favorite"
|
||||||
const identifier = `${group.filter_label.toLowerCase()}-${iconIdentifier}`
|
const identifier = `${group.filter_label.toLowerCase()}-${iconIdentifier}`
|
||||||
const cards = group.cardConnection.edges
|
const cards = group.cardConnection.edges
|
||||||
@@ -51,16 +50,43 @@ const carouselCardGroupsSchema = z
|
|||||||
groups.filter((group): group is NonNullable<typeof group> => group !== null)
|
groups.filter((group): group is NonNullable<typeof group> => group !== null)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const carouselCardGroupsNoFilterSchema = z
|
||||||
|
.array(
|
||||||
|
z
|
||||||
|
.object({
|
||||||
|
cardConnection: z.object({
|
||||||
|
edges: z.array(z.object({ node: contentCardSchema })),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.transform((group) => {
|
||||||
|
if (!group.cardConnection.edges.length) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
const cards = group.cardConnection.edges
|
||||||
|
.map((edge) => transformContentCard(edge.node))
|
||||||
|
.filter((card): card is NonNullable<typeof card> => card !== null)
|
||||||
|
.map((card) => ({
|
||||||
|
...card,
|
||||||
|
}))
|
||||||
|
return {
|
||||||
|
cards,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.transform((groups) =>
|
||||||
|
groups.filter((group): group is NonNullable<typeof group> => group !== null)
|
||||||
|
)
|
||||||
|
|
||||||
const carouselCardsWithFilters = z.object({
|
const carouselCardsWithFilters = z.object({
|
||||||
...commonFields,
|
...commonFields,
|
||||||
enable_filters: z.literal(true),
|
enable_filters: z.literal(true),
|
||||||
card_groups: carouselCardGroupsSchema,
|
card_groups: carouselCardGroupsFilteredSchema,
|
||||||
})
|
})
|
||||||
|
|
||||||
const carouselCardsWithoutFilters = z.object({
|
const carouselCardsWithoutFilters = z.object({
|
||||||
...commonFields,
|
...commonFields,
|
||||||
enable_filters: z.literal(false),
|
enable_filters: z.literal(false),
|
||||||
card_groups: carouselCardGroupsSchema,
|
card_groups: carouselCardGroupsNoFilterSchema,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const carouselCardsSchema = z.object({
|
export const carouselCardsSchema = z.object({
|
||||||
|
|||||||
Reference in New Issue
Block a user