@@ -5,11 +5,19 @@ import { CypressFields } from '../../utils/Cypress';
5
5
import { Product } from '../../protos/demo' ;
6
6
import ProductPrice from '../ProductPrice' ;
7
7
import * as S from './ProductCard.styled' ;
8
+ import { useState , useEffect } from 'react' ;
9
+ import { RequestInfo } from 'undici-types' ;
10
+ import { useNumberFlagValue } from '@openfeature/react-sdk' ;
8
11
9
12
interface IProps {
10
13
product : Product ;
11
14
}
12
15
16
+ async function getImageWithHeaders ( url : RequestInfo , headers : Record < string , string > ) {
17
+ const res = await fetch ( url , { headers } ) ;
18
+ return await res . blob ( ) ;
19
+ }
20
+
13
21
const ProductCard = ( {
14
22
product : {
15
23
id,
@@ -22,10 +30,20 @@ const ProductCard = ({
22
30
} ,
23
31
} ,
24
32
} : IProps ) => {
33
+ const imageSlowLoad = useNumberFlagValue ( 'imageSlowLoad' , 0 ) ;
34
+ const [ imageSrc , setImageSrc ] = useState < string > ( '' ) ;
35
+
36
+ useEffect ( ( ) => {
37
+ const headers = { 'x-envoy-fault-delay-request' : imageSlowLoad . toString ( ) , 'Cache-Control' : 'no-cache' } ;
38
+ getImageWithHeaders ( '/images/products/' + picture , headers ) . then ( blob => {
39
+ setImageSrc ( URL . createObjectURL ( blob ) ) ;
40
+ } ) ;
41
+ } , [ picture , imageSlowLoad ] ) ;
42
+
25
43
return (
26
44
< S . Link href = { `/product/${ id } ` } >
27
45
< S . ProductCard data-cy = { CypressFields . ProductCard } >
28
- < S . Image $src = { "/images/products/" + picture } />
46
+ < S . Image $src = { imageSrc } />
29
47
< div >
30
48
< S . ProductName > { name } </ S . ProductName >
31
49
< S . ProductPrice >
0 commit comments