@@ -7,8 +7,10 @@ import IconClose from 'assets/images/timeline-wall/btn-close.svg';
77import IconCheveronLeft from 'assets/images/timeline-wall/cheveron-left.svg' ;
88import IconCheveronRight from 'assets/images/timeline-wall/cheveron-right.svg' ;
99import PhotoVideoItem from 'components/GUIKit/PhotoVideoItem' ;
10+ import { v4 as uuidv4 } from 'uuid' ;
1011
1112import style from './styles.scss' ;
13+ import { isImage } from '../../../utils/url' ;
1214
1315function ModalPhotoViewer ( { onClose, selectedPhoto, photos } ) {
1416 const newPhotos = photos . map ( ( photo , index ) => ( { ...photo , id : index } ) ) ;
@@ -17,15 +19,17 @@ function ModalPhotoViewer({ onClose, selectedPhoto, photos }) {
1719 ( ) => _ . find ( newPhotos , { id : localSelectedPhoto } ) , [ localSelectedPhoto ] ,
1820 ) ;
1921
22+ const photosMapped = photos . map ( ( item , index ) => ( { ...item , id : index } ) ) ;
23+
2024 return (
2125 < Modal
2226 theme = { { container : style . container , overlay : style . overlay } }
2327 onCancel = { onClose }
2428 >
2529 < button styleName = "btn-close" onClick = { onClose } type = "button" > < IconClose /> </ button >
2630 < div styleName = "content" >
27- { selectedPhotoObject && ! selectedPhotoObject . videoThumnailUrl ? ( < img src = { selectedPhotoObject . url } alt = "main" /> ) : null }
28- { selectedPhotoObject && ! ! selectedPhotoObject . videoThumnailUrl ? (
31+ { selectedPhotoObject && isImage ( selectedPhotoObject . url ) ? ( < img src = { selectedPhotoObject . url } alt = "main" /> ) : null }
32+ { selectedPhotoObject && ! isImage ( selectedPhotoObject . url ) ? (
2933 < video controls >
3034 < source src = { selectedPhotoObject . url } />
3135 < track kind = "captions" />
@@ -36,42 +40,42 @@ function ModalPhotoViewer({ onClose, selectedPhoto, photos }) {
3640 < button
3741 styleName = "btn-left"
3842 onClick = { ( ) => {
39- let currentIndex = _ . findIndex ( photos , photo => photo . id === localSelectedPhoto ) ;
43+ let currentIndex = _ . findIndex ( photosMapped , photo => photo . id === localSelectedPhoto ) ;
4044 currentIndex -= 1 ;
4145 if ( currentIndex < 0 ) {
42- currentIndex = photos . length - 1 ;
46+ currentIndex = photosMapped . length - 1 ;
4347 }
44- setLocalSelectedPhoto ( photos [ currentIndex ] . id ) ;
48+ setLocalSelectedPhoto ( photosMapped [ currentIndex ] . id ) ;
4549 } }
4650 type = "button"
4751 > < IconCheveronLeft />
4852 </ button >
4953 < button
5054 styleName = "btn-right"
5155 onClick = { ( ) => {
52- let currentIndex = _ . findIndex ( photos , photo => photo . id === localSelectedPhoto ) ;
56+ let currentIndex = _ . findIndex ( photosMapped , photo => photo . id === localSelectedPhoto ) ;
5357 currentIndex += 1 ;
54- if ( currentIndex >= photos . length ) {
58+ if ( currentIndex >= photosMapped . length ) {
5559 currentIndex = 0 ;
5660 }
57- setLocalSelectedPhoto ( photos [ currentIndex ] . id ) ;
61+ setLocalSelectedPhoto ( photosMapped [ currentIndex ] . id ) ;
5862 } }
5963 type = "button"
6064 > < IconCheveronRight />
6165 </ button >
6266 </ div >
6367
6468 < div styleName = "bottom" >
65- { photos . map ( photo => (
69+ { photosMapped . map ( photo => (
6670 < PhotoVideoItem
6771 styleName = { cn ( 'photo-item' , {
6872 selected : photo . id === localSelectedPhoto ,
6973 } ) }
70- url = { photo . url }
74+ url = { photo . previewUrl || photo . url }
7175 videoThumnailUrl = { photo . videoThumnailUrl }
7276 isUrlPhoto = { ! photo . videoThumnailUrl }
7377 onClick = { ( ) => setLocalSelectedPhoto ( photo . id ) }
74- key = { photo . id }
78+ key = { uuidv4 ( ) }
7579 />
7680 ) ) }
7781 </ div >
0 commit comments