1
1
import { Box , Skeleton } from '@rocket.chat/fuselage' ;
2
- import React , { useEffect , useMemo , useState } from 'react' ;
2
+ import React , { memo , useEffect , useMemo , useState } from 'react' ;
3
3
4
4
import { useSurfaceType } from '../surfaces/SurfaceContext' ;
5
5
@@ -28,15 +28,15 @@ const fetchImageState = (img) => {
28
28
} ;
29
29
} ;
30
30
31
- const ImageBlock = ( { className, element , parser } ) => {
31
+ const ImageBlock = ( { className, blockElement , parser } ) => {
32
32
const surface = useSurfaceType ( ) ;
33
33
34
34
const alignment =
35
35
surface === 'banner' || surface === 'message' ? 'flex-start' : 'center' ;
36
36
37
37
const [ { loading, width, height } , setState ] = useState ( ( ) => {
38
38
const img = document . createElement ( 'img' ) ;
39
- img . src = element . imageUrl ;
39
+ img . src = blockElement . imageUrl ;
40
40
return fetchImageState ( img ) ;
41
41
} ) ;
42
42
@@ -48,7 +48,7 @@ const ImageBlock = ({ className, element, parser }) => {
48
48
} ;
49
49
50
50
img . addEventListener ( 'load' , handleLoad ) ;
51
- img . src = element . imageUrl ;
51
+ img . src = blockElement . imageUrl ;
52
52
53
53
if ( img . complete ) {
54
54
img . removeEventListener ( 'load' , handleLoad ) ;
@@ -58,7 +58,7 @@ const ImageBlock = ({ className, element, parser }) => {
58
58
return ( ) => {
59
59
img . removeEventListener ( 'load' , handleLoad ) ;
60
60
} ;
61
- } , [ element . imageUrl ] ) ;
61
+ } , [ blockElement . imageUrl ] ) ;
62
62
63
63
const style = useMemo (
64
64
( ) => ( {
@@ -67,9 +67,9 @@ const ImageBlock = ({ className, element, parser }) => {
67
67
backgroundPosition : '50%' ,
68
68
backgroundSize : 'cover' ,
69
69
backgroundColor : 'rgba(204, 204, 204, 38%)' ,
70
- backgroundImage : `url(${ element . imageUrl } )` ,
70
+ backgroundImage : `url(${ blockElement . imageUrl } )` ,
71
71
} ) ,
72
- [ element . imageUrl ]
72
+ [ blockElement . imageUrl ]
73
73
) ;
74
74
75
75
return (
@@ -81,9 +81,9 @@ const ImageBlock = ({ className, element, parser }) => {
81
81
alignItems = { alignment }
82
82
>
83
83
< Box overflow = 'hidden' width = { width } >
84
- { element . title && (
84
+ { blockElement . title && (
85
85
< Box fontScale = 'c1' color = 'info' withTruncatedText marginBlockEnd = { 4 } >
86
- { parser . plainText ( element . title , - 1 , 0 ) }
86
+ { parser . plainText ( blockElement . title , - 1 , 0 ) }
87
87
</ Box >
88
88
) }
89
89
{ loading ? (
@@ -95,12 +95,12 @@ const ImageBlock = ({ className, element, parser }) => {
95
95
width = { width }
96
96
height = { height }
97
97
style = { style }
98
- aria-label = { element . altText }
98
+ aria-label = { blockElement . altText }
99
99
/>
100
100
) }
101
101
</ Box >
102
102
</ Box >
103
103
) ;
104
104
} ;
105
105
106
- export default ImageBlock ;
106
+ export default memo ( ImageBlock ) ;
0 commit comments