From ed7546aede8ef26c19ea6feb40f84fd6ca8bac4d Mon Sep 17 00:00:00 2001 From: Seif Ghezala Date: Wed, 16 Oct 2024 14:17:38 +0400 Subject: [PATCH] Update video input --- storefront/components/sections/hero/index.tsx | 23 +- storefront/components/shared/mux-video.tsx | 113 --------- storefront/components/shared/sanity-image.tsx | 122 +++++++++- storefront/components/shared/video.tsx | 69 ++++++ storefront/data/sanity/queries/section.ts | 11 - storefront/next.config.mjs | 1 - storefront/package.json | 2 +- storefront/pnpm-lock.yaml | 225 +----------------- storefront/sanity.config.ts | 2 - storefront/sanity/schemas/index.ts | 2 + storefront/sanity/schemas/objects/video.ts | 21 ++ storefront/sanity/schemas/sections/hero.ts | 2 +- 12 files changed, 229 insertions(+), 364 deletions(-) delete mode 100644 storefront/components/shared/mux-video.tsx create mode 100644 storefront/components/shared/video.tsx create mode 100644 storefront/sanity/schemas/objects/video.ts diff --git a/storefront/components/sections/hero/index.tsx b/storefront/components/sections/hero/index.tsx index d3bf01a..050561e 100644 --- a/storefront/components/sections/hero/index.tsx +++ b/storefront/components/sections/hero/index.tsx @@ -1,21 +1,15 @@ -import MuxVideo from "@/components/shared/mux-video"; import {SanityImage} from "@/components/shared/sanity-image"; +import Video from "@/components/shared/video"; import {stegaClean} from "@sanity/client/stega"; -import React from "react"; import type {ModularPageSection} from "../types"; import LargeHero from "./large-hero"; import SimpleHero from "./simple-hero"; -interface VideoData { - playbackId?: string; - resolution?: string; -} - export default function Hero(props: ModularPageSection<"section.hero">) { const mediaType = stegaClean(props.mediaType); - const video = stegaClean(props.video?.asset) as unknown as VideoData; + const video = props.video; const largeImage = stegaClean(props.largeImage); return (
) { {mediaType === "image" && } {mediaType === "video" && video && ( - +
+
)} {mediaType === "largeImage" && largeImage && ( diff --git a/storefront/components/shared/mux-video.tsx b/storefront/components/shared/mux-video.tsx deleted file mode 100644 index 5ecfb91..0000000 --- a/storefront/components/shared/mux-video.tsx +++ /dev/null @@ -1,113 +0,0 @@ -"use client"; - -import useInView from "@/hooks/use-in-view"; -import Image, {getImageProps} from "next/image"; -import React, {useEffect} from "react"; -import {preload} from "react-dom"; - -export type MuxVideoProps = { - loading?: "eager" | "lazy"; - video?: { - playbackId?: string; - resolution?: string; - }; -} & Omit; - -export default function MuxVideo({ - loading, - video, - ...videoProps -}: MuxVideoProps) { - const {playbackId, resolution} = video ?? {}; - - if (!playbackId || !resolution) { - return null; - } - - const mp4Url = `https://stream.mux.com/${playbackId}/${ - resolution === "SD" ? "medium" : "high" - }.mp4`; - - const webmUrl = `https://stream.mux.com/${playbackId}/${ - resolution === "SD" ? "medium" : "high" - }.webm`; - - const { - props: {src: poster}, - } = getImageProps({ - alt: "", - fill: true, - src: `https://image.mux.com/${playbackId}/thumbnail.webp?fit_mode=smartcrop&time=0`, - }); - - if (loading === "eager") { - preload(poster, { - as: "image", - fetchPriority: "high", - }); - - return ( -