diff --git a/apps/infoalloggi/src/components/annuncio_card.tsx b/apps/infoalloggi/src/components/annuncio_card.tsx index 5ebe84f..0c894d5 100644 --- a/apps/infoalloggi/src/components/annuncio_card.tsx +++ b/apps/infoalloggi/src/components/annuncio_card.tsx @@ -20,6 +20,7 @@ import { import { camereTesti, handleConsegna } from "~/lib/annuncio_details"; import { cn, formatCurrency } from "~/lib/utils"; import { useTranslation } from "~/providers/I18nProvider"; +import { VideoPlayer } from "./videoPlayer"; type CardAnnuncioProps = { id: number; @@ -205,9 +206,11 @@ export const CardAnnuncio = ({ export const CarouselAnnuncio = ({ single, immagini, + videos, }: { single?: boolean; immagini: string[] | null; + videos: string[] | null; }) => { const [openModal, setOpenModal] = useState(false); const [idxModal, setIdxModal] = useState(0); @@ -215,7 +218,6 @@ export const CarouselAnnuncio = ({ setIdxModal(position); setOpenModal(true); } - return ( <>
@@ -245,11 +247,43 @@ export const CarouselAnnuncio = ({ width={800} /> handleOpenModal(idx)} /> ))} + {videos?.map((video, idx) => { + if (!video) return null; + if (video.includes("youtu")) { + return null; + } else { + return ( + + + + + handleOpenModal(immagini?.length || 0 + idx) + } + /> + + ); + } + })} {`carousel-img-${idx}`} ))} + {videos?.map((video) => { + if (!video) return null; + if (video.includes("youtu")) { + return null; + } else { + return ( + + + + ); + } + })} (null); + const inView = useInView(videoRef); + + useEffect(() => { + if (!inView) { + setIsPlaying(false); + } + }, [inView]); const aspectRatioClasses = { square: "aspect-square", @@ -36,6 +44,7 @@ export function VideoPlayer({ aspectRatioClasses[aspectRatio], className, )} + ref={videoRef} > {!isPlaying ? ( diff --git a/apps/infoalloggi/src/forms/FormEditAnnuncio.tsx b/apps/infoalloggi/src/forms/FormEditAnnuncio.tsx index 191915b..2d7d2e9 100644 --- a/apps/infoalloggi/src/forms/FormEditAnnuncio.tsx +++ b/apps/infoalloggi/src/forms/FormEditAnnuncio.tsx @@ -454,18 +454,15 @@ export const AnnuncioEditForm = ({ data }: { data: Annunci }) => { Imagini Annuncio - {data.url_immagini && data.url_immagini.length > 0 ? ( - `/go-api/images/get/${v}`, - )} - single - /> - ) : ( -
- Nessuna immagine disponibile -
- )} + ) || null + } + single + videos={data.url_video} + />
diff --git a/apps/infoalloggi/src/pages/annuncio/[cod].tsx b/apps/infoalloggi/src/pages/annuncio/[cod].tsx index 74c2943..931dd59 100644 --- a/apps/infoalloggi/src/pages/annuncio/[cod].tsx +++ b/apps/infoalloggi/src/pages/annuncio/[cod].tsx @@ -133,7 +133,10 @@ const AnnuncioView = ({ cod, flag }: Omit) => {
- +