@@ -7,8 +7,10 @@ import IconClose from 'assets/images/timeline-wall/btn-close.svg';
7
7
import IconCheveronLeft from 'assets/images/timeline-wall/cheveron-left.svg' ;
8
8
import IconCheveronRight from 'assets/images/timeline-wall/cheveron-right.svg' ;
9
9
import PhotoVideoItem from 'components/GUIKit/PhotoVideoItem' ;
10
+ import { v4 as uuidv4 } from 'uuid' ;
10
11
11
12
import style from './styles.scss' ;
13
+ import { isImage } from '../../../utils/url' ;
12
14
13
15
function ModalPhotoViewer ( { onClose, selectedPhoto, photos } ) {
14
16
const newPhotos = photos . map ( ( photo , index ) => ( { ...photo , id : index } ) ) ;
@@ -17,15 +19,17 @@ function ModalPhotoViewer({ onClose, selectedPhoto, photos }) {
17
19
( ) => _ . find ( newPhotos , { id : localSelectedPhoto } ) , [ localSelectedPhoto ] ,
18
20
) ;
19
21
22
+ const photosMapped = photos . map ( ( item , index ) => ( { ...item , id : index } ) ) ;
23
+
20
24
return (
21
25
< Modal
22
26
theme = { { container : style . container , overlay : style . overlay } }
23
27
onCancel = { onClose }
24
28
>
25
29
< button styleName = "btn-close" onClick = { onClose } type = "button" > < IconClose /> </ button >
26
30
< 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 ) ? (
29
33
< video controls >
30
34
< source src = { selectedPhotoObject . url } />
31
35
< track kind = "captions" />
@@ -36,42 +40,42 @@ function ModalPhotoViewer({ onClose, selectedPhoto, photos }) {
36
40
< button
37
41
styleName = "btn-left"
38
42
onClick = { ( ) => {
39
- let currentIndex = _ . findIndex ( photos , photo => photo . id === localSelectedPhoto ) ;
43
+ let currentIndex = _ . findIndex ( photosMapped , photo => photo . id === localSelectedPhoto ) ;
40
44
currentIndex -= 1 ;
41
45
if ( currentIndex < 0 ) {
42
- currentIndex = photos . length - 1 ;
46
+ currentIndex = photosMapped . length - 1 ;
43
47
}
44
- setLocalSelectedPhoto ( photos [ currentIndex ] . id ) ;
48
+ setLocalSelectedPhoto ( photosMapped [ currentIndex ] . id ) ;
45
49
} }
46
50
type = "button"
47
51
> < IconCheveronLeft />
48
52
</ button >
49
53
< button
50
54
styleName = "btn-right"
51
55
onClick = { ( ) => {
52
- let currentIndex = _ . findIndex ( photos , photo => photo . id === localSelectedPhoto ) ;
56
+ let currentIndex = _ . findIndex ( photosMapped , photo => photo . id === localSelectedPhoto ) ;
53
57
currentIndex += 1 ;
54
- if ( currentIndex >= photos . length ) {
58
+ if ( currentIndex >= photosMapped . length ) {
55
59
currentIndex = 0 ;
56
60
}
57
- setLocalSelectedPhoto ( photos [ currentIndex ] . id ) ;
61
+ setLocalSelectedPhoto ( photosMapped [ currentIndex ] . id ) ;
58
62
} }
59
63
type = "button"
60
64
> < IconCheveronRight />
61
65
</ button >
62
66
</ div >
63
67
64
68
< div styleName = "bottom" >
65
- { photos . map ( photo => (
69
+ { photosMapped . map ( photo => (
66
70
< PhotoVideoItem
67
71
styleName = { cn ( 'photo-item' , {
68
72
selected : photo . id === localSelectedPhoto ,
69
73
} ) }
70
- url = { photo . url }
74
+ url = { photo . previewUrl || photo . url }
71
75
videoThumnailUrl = { photo . videoThumnailUrl }
72
76
isUrlPhoto = { ! photo . videoThumnailUrl }
73
77
onClick = { ( ) => setLocalSelectedPhoto ( photo . id ) }
74
- key = { photo . id }
78
+ key = { uuidv4 ( ) }
75
79
/>
76
80
) ) }
77
81
</ div >
0 commit comments