* fix(BOOK-240): Added support for multiple sources and fixed issue with play/pause on mobile * fix(BOOK-240): Pausing hero video when scrolling out of view Approved-by: Christel Westerberg
81 lines
1.9 KiB
TypeScript
81 lines
1.9 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import { Lang } from "@scandic-hotels/common/constants/language"
|
|
import { focalPointSchema } from "@scandic-hotels/common/utils/focalPoint"
|
|
|
|
import { assetSystemSchema } from "./system"
|
|
|
|
export const videoSchema = z.object({
|
|
sourceConnection: z.object({
|
|
edges: z.array(
|
|
z.object({
|
|
node: z.object({
|
|
url: z.string().url(),
|
|
content_type: z.string(),
|
|
}),
|
|
})
|
|
),
|
|
}),
|
|
focal_point: focalPointSchema.nullish(),
|
|
captions: z.array(
|
|
z.object({
|
|
is_default: z.boolean(),
|
|
fileConnection: z.object({
|
|
edges: z.array(
|
|
z.object({
|
|
node: z.object({
|
|
url: z.string().url(),
|
|
}),
|
|
})
|
|
),
|
|
}),
|
|
language: z.nativeEnum(Lang),
|
|
})
|
|
),
|
|
})
|
|
|
|
export const transformedVideoSchema = videoSchema
|
|
.nullish()
|
|
.transform((video) => {
|
|
const sources =
|
|
video?.sourceConnection.edges.map((edge) => ({
|
|
src: edge.node.url,
|
|
type: edge.node.content_type,
|
|
})) || []
|
|
|
|
if (!video || !sources.length) {
|
|
return null
|
|
}
|
|
|
|
const captions = video.captions
|
|
.filter((caption) => caption.fileConnection.edges[0]?.node.url)
|
|
.map((caption) => ({
|
|
src: caption.fileConnection.edges[0]?.node.url || "",
|
|
srcLang: caption.language,
|
|
isDefault: caption.is_default,
|
|
}))
|
|
|
|
return {
|
|
sources,
|
|
focalPoint: video.focal_point
|
|
? { x: video.focal_point.x, y: video.focal_point.y }
|
|
: { x: 50, y: 50 },
|
|
captions,
|
|
}
|
|
})
|
|
|
|
export const videoRefSchema = z.object({
|
|
sourceConnection: z.object({
|
|
edges: z.array(
|
|
z.object({
|
|
node: z.object({
|
|
system: assetSystemSchema,
|
|
}),
|
|
})
|
|
),
|
|
}),
|
|
})
|
|
|
|
export type Video = z.output<typeof transformedVideoSchema>
|
|
export type VideoCaptions = NonNullable<Video>["captions"]
|