@@ -11,7 +11,7 @@ import React, {
11
11
useState ,
12
12
VideoHTMLAttributes
13
13
} from "react" ;
14
- import styled , { css } from "styled-components" ;
14
+ import styled , { css , CSSProperties } from "styled-components" ;
15
15
16
16
import { colors } from "../../lib/styles/colors" ;
17
17
import { zIndex } from "../../lib/styles/zIndex" ;
@@ -23,12 +23,12 @@ const StyledMuteButton = styled(MuteButton)`
23
23
position: absolute;
24
24
top: 1rem;
25
25
right: 1rem;
26
+ z-index: 1;
26
27
` ;
27
28
const VideoWrapper = styled . div < { $hasOnClick ?: boolean } > `
28
29
overflow: hidden;
29
30
position: relative;
30
31
z-index: ${ zIndex . OfferCard } ;
31
- height: 0;
32
32
padding-top: 120%;
33
33
font-size: inherit;
34
34
${ ( { $hasOnClick } ) =>
@@ -63,8 +63,15 @@ const VideoContainer = styled.video`
63
63
object-fit : contain;
64
64
` ;
65
65
66
- const VideoPlaceholder = styled . div `
67
- position: absolute;
66
+ const VideoPlaceholder = styled . div < { $position ?: CSSProperties [ "position" ] } > `
67
+ ${ ( { $position } ) =>
68
+ $position
69
+ ? css `
70
+ position : ${ $position } ;
71
+ `
72
+ : css `
73
+ position : absolute;
74
+ ` }
68
75
top: 0;
69
76
height: 100%;
70
77
width: 100%;
@@ -120,6 +127,8 @@ const Video: React.FC<IVideo & React.HTMLAttributes<HTMLDivElement>> = ({
120
127
ipfsMetadataStorage
121
128
) ;
122
129
setVideoSrc ( base64str as string ) ;
130
+ setIsLoaded ( true ) ;
131
+ setIsError ( false ) ;
123
132
} catch ( error ) {
124
133
console . error ( "error in Video" , error ) ;
125
134
Sentry . captureException ( error ) ;
@@ -132,8 +141,13 @@ const Video: React.FC<IVideo & React.HTMLAttributes<HTMLDivElement>> = ({
132
141
}
133
142
}
134
143
if ( ! isLoaded && videoSrc === null ) {
135
- if ( src ?. includes ( "ipfs://" ) ) {
136
- const newString = src . split ( "//" ) ;
144
+ if (
145
+ src ?. startsWith ( "ipfs://" ) ||
146
+ src ?. startsWith ( "https://bosonprotocol.infura-ipfs.io/ipfs/" )
147
+ ) {
148
+ const newString = src ?. startsWith ( "ipfs://" )
149
+ ? src . split ( "//" )
150
+ : src . split ( "https://bosonprotocol.infura-ipfs.io/ipfs/" ) ;
137
151
const CID = newString [ newString . length - 1 ] ;
138
152
fetchData ( `ipfs://${ CID } ` ) ;
139
153
} else if ( src ?. startsWith ( "undefined" ) && src ?. length > 9 ) {
@@ -145,12 +159,6 @@ const Video: React.FC<IVideo & React.HTMLAttributes<HTMLDivElement>> = ({
145
159
}
146
160
} , [ ] ) ; // eslint-disable-line
147
161
148
- useEffect ( ( ) => {
149
- if ( videoSrc !== null ) {
150
- setTimeout ( ( ) => setIsLoaded ( true ) , 100 ) ;
151
- }
152
- } , [ videoSrc ] ) ;
153
-
154
162
const mp4Src = useMemo ( ( ) => {
155
163
const octetSrc =
156
164
videoSrc ?. startsWith ( "data:application/octet-stream;base64," ) || false ;
@@ -179,13 +187,14 @@ const Video: React.FC<IVideo & React.HTMLAttributes<HTMLDivElement>> = ({
179
187
videoRef . current . play ( ) ;
180
188
}
181
189
} , [ muted ] ) ;
190
+
182
191
if ( ! isLoaded && ! isError ) {
183
192
if ( ComponentWhileLoading ) {
184
193
return < ComponentWhileLoading /> ;
185
194
}
186
195
return (
187
196
< VideoWrapper { ...rest } >
188
- < VideoPlaceholder >
197
+ < VideoPlaceholder $position = "static" >
189
198
< Typography tag = "div" >
190
199
< Loading />
191
200
</ Typography >
@@ -197,7 +206,7 @@ const Video: React.FC<IVideo & React.HTMLAttributes<HTMLDivElement>> = ({
197
206
if ( isLoaded && isError ) {
198
207
return (
199
208
< VideoWrapper { ...rest } >
200
- < VideoPlaceholder data-video-placeholder >
209
+ < VideoPlaceholder data-video-placeholder $position = "static" >
201
210
{ showPlaceholderText ? (
202
211
< VideoIcon size = { 50 } color = { colors . white } />
203
212
) : (
@@ -227,6 +236,10 @@ const Video: React.FC<IVideo & React.HTMLAttributes<HTMLDivElement>> = ({
227
236
data-testid = { dataTestId }
228
237
{ ...videoProps }
229
238
src = { mp4Src || "" }
239
+ onError = { ( ) => {
240
+ setIsLoaded ( true ) ;
241
+ setIsError ( true ) ;
242
+ } }
230
243
/>
231
244
</ >
232
245
) }
0 commit comments