Skip to content

Commit 98cef23

Browse files
authored
Merge pull request #6688 from nursoltan-s/timeline-wall-final-fix
fix upload bugs
2 parents 4f68c9b + 887ed74 commit 98cef23

File tree

5 files changed

+25
-16
lines changed

5 files changed

+25
-16
lines changed

src/shared/containers/timeline-wall/modal-photo-viewer/index.jsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import IconClose from 'assets/images/timeline-wall/btn-close.svg';
77
import IconCheveronLeft from 'assets/images/timeline-wall/cheveron-left.svg';
88
import IconCheveronRight from 'assets/images/timeline-wall/cheveron-right.svg';
99
import PhotoVideoItem from 'components/GUIKit/PhotoVideoItem';
10+
import { v4 as uuidv4 } from 'uuid';
1011

1112
import style from './styles.scss';
13+
import { isImage } from '../../../utils/url';
1214

1315
function 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>

src/shared/containers/timeline-wall/timeline-events/events/event-item/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function EventItem({
6868
{eventItem.mediaFiles.map(photo => (
6969
<PhotoVideoItem
7070
styleName="photo-item hide-mobile"
71-
url={photo.url}
71+
url={photo.previewUrl || photo.url}
7272
videoThumnailUrl={photo.videoThumnailUrl}
7373
isUrlPhoto={!photo.videoThumnailUrl}
7474
key={photo.id}

src/shared/reducers/timelineWall.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Reducer for state.timelineWall
33
*/
44
import actions from 'actions/timelineWall';
5+
import _ from 'lodash';
56
import { handleActions } from 'redux-actions';
67
import { DEFAULT_AVATAR_URL } from '../utils/url';
78

@@ -70,10 +71,11 @@ function onPendingApprovalInit(state) {
7071
* @param {Object} payload The payload.
7172
*/
7273
function onPendingApprovalDone(state, { payload }) {
74+
const approvals = _.isArray(payload) ? payload : [];
7375
return {
7476
...state,
7577
loading: false,
76-
pendingApprovals: payload,
78+
pendingApprovals: approvals,
7779
};
7880
}
7981

src/shared/services/timelineWall.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ export const createEvent = async (tokenV3, formData) => {
7070
form.append('title', formData.eventName);
7171
form.append('description', formData.description);
7272
form.append('eventDate', formData.date);
73-
if (formData.files) {
74-
form.append('mediaFiles', new File(formData.files || [], formData.eventName));
73+
if (formData.files && formData.files.length) {
74+
formData.files.forEach((file) => {
75+
const fileExt = (file.type && file.type.length > 1) ? file.type.split('/')[1] : '';
76+
form.append('mediaFiles', new File([file], `${formData.eventName}.${fileExt}`, { type: file.type }));
77+
});
7578
}
7679

7780
try {

src/shared/utils/url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export function isImage(url) {
128128
}
129129

130130
export function isVideo(url) {
131-
return /\.(mp4|mov|wmv|avi|mkv|flv)$/.test(`${url}`.toLowerCase());
131+
return /\.(mp4|mov|wmv|webm|avi|mkv|flv)$/.test(`${url}`.toLowerCase());
132132
}
133133

134134
export const DEFAULT_AVATAR_URL = 'https://images.ctfassets.net/b5f1djy59z3a/4PTwZVSf3W7qgs9WssqbVa/4c51312671a4b9acbdfd7f5e22320b62/default_avatar.svg';

0 commit comments

Comments
 (0)