@@ -47,7 +47,9 @@ const Card = (props: NotificationCardProps): ReactElement => {
4747 disableAutoMarkAsRead,
4848 hideDelete = false ,
4949 onAvatarClick,
50- deleteIcon = null
50+ deleteIcon = null ,
51+ hideMediaThumbnail = false ,
52+ onMediaThumbnailClick
5153 } = cardProps ;
5254 const { markAsReadById } = useSiren ( ) ;
5355
@@ -57,18 +59,26 @@ const Card = (props: NotificationCardProps): ReactElement => {
5759 return darkMode ? require ( '../assets/emptyDark.png' ) : require ( '../assets/emptyLight.png' ) ;
5860 } ;
5961
62+ const failedState = ( ) => {
63+ return darkMode
64+ ? require ( '../assets/failedImageDark.png' )
65+ : require ( '../assets/failedImageLight.png' ) ;
66+ } ;
67+
68+ const avatarUrl = notification ?. message ?. avatar ?. imageUrl || '' ;
69+ const thumbnailUrl = notification ?. message ?. thumbnailUrl || '' ;
70+
6071 const [ imageSource , setImageSource ] = useState (
61- notification ?. message ?. avatar ?. imageUrl ?. length > 0
62- ? { uri : notification . message ?. avatar ?. imageUrl }
63- : emptyState ( )
72+ avatarUrl ?. length > 0 ? { uri : avatarUrl } : emptyState ( )
73+ ) ;
74+
75+ const [ mediaSource , setMediaSource ] = useState (
76+ thumbnailUrl ?. length > 0 ? { uri : thumbnailUrl } : emptyState ( )
6477 ) ;
6578
6679 useEffect ( ( ) => {
67- setImageSource (
68- notification ?. message ?. avatar ?. imageUrl ?. length > 0
69- ? { uri : notification . message ?. avatar ?. imageUrl }
70- : emptyState ( )
71- ) ;
80+ setImageSource ( avatarUrl ?. length > 0 ? { uri : avatarUrl } : emptyState ( ) ) ;
81+ setMediaSource ( thumbnailUrl ?. length > 0 ? { uri : thumbnailUrl } : failedState ( ) ) ;
7282 } , [ notification , darkMode ] ) ;
7383
7484 const cardClick = ( ) : void => {
@@ -80,10 +90,18 @@ const Card = (props: NotificationCardProps): ReactElement => {
8090 setImageSource ( emptyState ( ) ) ;
8191 } ;
8292
93+ const onErrorMedia = ( ) : void => {
94+ setMediaSource ( failedState ( ) ) ;
95+ } ;
96+
8397 const avatarClick = ( ) => {
8498 if ( onAvatarClick ) onAvatarClick ( notification ) ;
8599 } ;
86100
101+ const mediaClick = ( ) => {
102+ if ( onMediaThumbnailClick ) onMediaThumbnailClick ( notification ) ;
103+ } ;
104+
87105 const renderAvatar = useMemo ( ( ) : JSX . Element => {
88106 return (
89107 < View style = { style . cardIconContainer } >
@@ -104,6 +122,18 @@ const Card = (props: NotificationCardProps): ReactElement => {
104122 ) ;
105123 } , [ styles , darkMode , imageSource , onAvatarClick ] ) ;
106124
125+ const renderMediaThumbnail = useMemo ( ( ) : JSX . Element => {
126+ return (
127+ < TouchableOpacity
128+ style = { [ style . mediaContainer , styles . mediaContainer ] }
129+ disabled = { Boolean ( ! onMediaThumbnailClick ) }
130+ onPress = { mediaClick }
131+ >
132+ < Image source = { mediaSource } resizeMode = 'cover' style = { style . icon } onError = { onErrorMedia } />
133+ </ TouchableOpacity >
134+ ) ;
135+ } , [ darkMode , mediaSource , onMediaThumbnailClick ] ) ;
136+
107137 const onDeleteItem = async ( ) : Promise < void > => {
108138 const isSuccess = await onDelete ( notification . id , false ) ;
109139
@@ -151,9 +181,14 @@ const Card = (props: NotificationCardProps): ReactElement => {
151181 { notification . message ?. subHeader }
152182 </ Text >
153183 ) }
154- < Text numberOfLines = { 2 } style = { [ style . cardDescription , styles . cardDescription ] } >
155- { notification . message ?. body }
156- </ Text >
184+ { Boolean ( notification . message ?. body ) && (
185+ < Text numberOfLines = { 2 } style = { [ style . cardDescription , styles . cardDescription ] } >
186+ { notification . message ?. body }
187+ </ Text >
188+ ) }
189+ { ! hideMediaThumbnail &&
190+ Boolean ( notification . message ?. thumbnailUrl ) &&
191+ renderMediaThumbnail }
157192 < View style = { style . dateContainer } >
158193 < TimerIcon styles = { styles } />
159194 < Text style = { [ style . dateStyle , styles . dateStyle ] } >
@@ -228,6 +263,14 @@ const style = StyleSheet.create({
228263 } ,
229264 transparent : {
230265 backgroundColor : 'transparent'
266+ } ,
267+ mediaContainer : {
268+ width : '100%' ,
269+ height : 130 ,
270+ borderRadius : 6 ,
271+ marginBottom : 10 ,
272+ overflow : 'hidden' ,
273+ backgroundColor : '#D3D3D3'
231274 }
232275} ) ;
233276
0 commit comments