@@ -11,10 +11,12 @@ function YouTubeVideoPlayer({ mediaContent }: { mediaContent: any }) {
11
11
const [ showVideo , setShowVideo ] = useState ( false ) ;
12
12
13
13
if ( showVideo ) {
14
+ const autoplayUrl = `${ mediaContent . videoSrc } &autoplay=1` ;
15
+
14
16
return (
15
17
< div className = "relative w-full aspect-[16/9]" >
16
18
< iframe
17
- src = { mediaContent . videoSrc }
19
+ src = { autoplayUrl }
18
20
title = { mediaContent . alt || "YouTube Video" }
19
21
allow = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
20
22
allowFullScreen
@@ -54,22 +56,70 @@ function YouTubeVideoPlayer({ mediaContent }: { mediaContent: any }) {
54
56
) ;
55
57
}
56
58
59
+ function VideoPlayer ( { mediaContent } : { mediaContent : any } ) {
60
+ const getSizeClasses = ( size : string ) => {
61
+ switch ( size ) {
62
+ case "small" :
63
+ return "max-w-md mx-auto" ;
64
+ case "medium" :
65
+ return "max-w-2xl mx-auto" ;
66
+ case "large" :
67
+ return "max-w-4xl mx-auto" ;
68
+ default :
69
+ return "max-w-2xl mx-auto" ;
70
+ }
71
+ } ;
72
+
73
+ const videoUrl =
74
+ typeof mediaContent . video === "string"
75
+ ? mediaContent . video
76
+ : mediaContent . video ?. url || mediaContent . video ;
77
+
78
+ if ( ! videoUrl ) {
79
+ return null ;
80
+ }
81
+
82
+ return (
83
+ < div className = { `w-full ${ getSizeClasses ( mediaContent . size || "medium" ) } ` } >
84
+ < video
85
+ src = { videoUrl }
86
+ width = { mediaContent . width || undefined }
87
+ height = { mediaContent . height || undefined }
88
+ autoPlay
89
+ loop
90
+ muted
91
+ playsInline
92
+ className = "w-full h-auto rounded-lg shadow-lg"
93
+ >
94
+ { mediaContent . altText && (
95
+ < p > Your browser doesn't support HTML video. { mediaContent . altText } </ p >
96
+ ) }
97
+ </ video >
98
+ </ div >
99
+ ) ;
100
+ }
101
+
57
102
function renderMediaContent ( mediaContent : any ) {
58
103
if ( mediaContent . __typename . includes ( "YoutubeVideo" ) ) {
59
104
return < YouTubeVideoPlayer mediaContent = { mediaContent } /> ;
60
105
}
61
106
if ( mediaContent . __typename . includes ( "Image" ) ) {
62
107
return (
63
108
< div >
64
- < Image
65
- src = { mediaContent . image . url }
66
- alt = { mediaContent . image . alt || "Untitled Image" }
67
- width = { mediaContent . image . width }
68
- height = { mediaContent . image . height }
69
- />
109
+ { mediaContent ?. image ?. url && (
110
+ < Image
111
+ src = { mediaContent . image . url }
112
+ alt = { mediaContent ?. image ?. alt || "Untitled Image" }
113
+ width = { mediaContent ?. image ?. width || 500 }
114
+ height = { mediaContent ?. image ?. height || 500 }
115
+ />
116
+ ) }
70
117
</ div >
71
118
) ;
72
119
}
120
+ if ( mediaContent . __typename . includes ( "Video" ) ) {
121
+ return < VideoPlayer mediaContent = { mediaContent } /> ;
122
+ }
73
123
return null ;
74
124
}
75
125
@@ -86,7 +136,9 @@ function renderFeatures(features: any[]) {
86
136
< div className = "flex flex-col" >
87
137
{ features . map ( ( feature , index ) => (
88
138
< div
89
- key = { `${ feature . title || 'untitled' } - ${ index } -${ feature . description || '' } ` }
139
+ key = { `${ feature . title || "untitled" } - ${ index } -${
140
+ feature . description || ""
141
+ } `}
90
142
data-tina-field = { tinaField ( feature ) }
91
143
className = { `p-8 ${
92
144
features . length === 2 && index === 0
@@ -162,7 +214,11 @@ export default function MediaFeature({
162
214
< div className = "py-10" >
163
215
{ data . MediaBlock &&
164
216
data . MediaBlock . map ( ( block : any , index : number ) => (
165
- < div key = { `media-block-${ index } -${ block . isMediaOnRight ? 'right' : 'left' } ` } >
217
+ < div
218
+ key = { `media-block-${ index } -${
219
+ block . isMediaOnRight ? "right" : "left"
220
+ } `}
221
+ >
166
222
{ mediaBlock ( block ) }
167
223
</ div >
168
224
) ) }
0 commit comments