From 887ed74a82e7f44c6e2c32deb31de4b9d6e0efb9 Mon Sep 17 00:00:00 2001 From: Nursoltan Saipolda Date: Wed, 19 Oct 2022 02:57:07 +0800 Subject: [PATCH] fix upload bugs --- .../modal-photo-viewer/index.jsx | 26 +++++++++++-------- .../events/event-item/index.jsx | 2 +- src/shared/reducers/timelineWall.js | 4 ++- src/shared/services/timelineWall.js | 7 +++-- src/shared/utils/url.js | 2 +- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/shared/containers/timeline-wall/modal-photo-viewer/index.jsx b/src/shared/containers/timeline-wall/modal-photo-viewer/index.jsx index 2b8b1fa9cc..70392afb98 100644 --- a/src/shared/containers/timeline-wall/modal-photo-viewer/index.jsx +++ b/src/shared/containers/timeline-wall/modal-photo-viewer/index.jsx @@ -7,8 +7,10 @@ import IconClose from 'assets/images/timeline-wall/btn-close.svg'; import IconCheveronLeft from 'assets/images/timeline-wall/cheveron-left.svg'; import IconCheveronRight from 'assets/images/timeline-wall/cheveron-right.svg'; import PhotoVideoItem from 'components/GUIKit/PhotoVideoItem'; +import { v4 as uuidv4 } from 'uuid'; import style from './styles.scss'; +import { isImage } from '../../../utils/url'; function ModalPhotoViewer({ onClose, selectedPhoto, photos }) { const newPhotos = photos.map((photo, index) => ({ ...photo, id: index })); @@ -17,6 +19,8 @@ function ModalPhotoViewer({ onClose, selectedPhoto, photos }) { () => _.find(newPhotos, { id: localSelectedPhoto }), [localSelectedPhoto], ); + const photosMapped = photos.map((item, index) => ({ ...item, id: index })); + return (
- {selectedPhotoObject && !selectedPhotoObject.videoThumnailUrl ? (main) : null} - {selectedPhotoObject && !!selectedPhotoObject.videoThumnailUrl ? ( + {selectedPhotoObject && isImage(selectedPhotoObject.url) ? (main) : null} + {selectedPhotoObject && !isImage(selectedPhotoObject.url) ? (
- {photos.map(photo => ( + {photosMapped.map(photo => ( setLocalSelectedPhoto(photo.id)} - key={photo.id} + key={uuidv4()} /> ))}
diff --git a/src/shared/containers/timeline-wall/timeline-events/events/event-item/index.jsx b/src/shared/containers/timeline-wall/timeline-events/events/event-item/index.jsx index cf7acd81a1..6c9f25fd86 100644 --- a/src/shared/containers/timeline-wall/timeline-events/events/event-item/index.jsx +++ b/src/shared/containers/timeline-wall/timeline-events/events/event-item/index.jsx @@ -68,7 +68,7 @@ function EventItem({ {eventItem.mediaFiles.map(photo => ( { form.append('title', formData.eventName); form.append('description', formData.description); form.append('eventDate', formData.date); - if (formData.files) { - form.append('mediaFiles', new File(formData.files || [], formData.eventName)); + if (formData.files && formData.files.length) { + formData.files.forEach((file) => { + const fileExt = (file.type && file.type.length > 1) ? file.type.split('/')[1] : ''; + form.append('mediaFiles', new File([file], `${formData.eventName}.${fileExt}`, { type: file.type })); + }); } try { diff --git a/src/shared/utils/url.js b/src/shared/utils/url.js index dc4c999f26..60f083112c 100644 --- a/src/shared/utils/url.js +++ b/src/shared/utils/url.js @@ -128,7 +128,7 @@ export function isImage(url) { } export function isVideo(url) { - return /\.(mp4|mov|wmv|avi|mkv|flv)$/.test(`${url}`.toLowerCase()); + return /\.(mp4|mov|wmv|webm|avi|mkv|flv)$/.test(`${url}`.toLowerCase()); } export const DEFAULT_AVATAR_URL = 'https://images.ctfassets.net/b5f1djy59z3a/4PTwZVSf3W7qgs9WssqbVa/4c51312671a4b9acbdfd7f5e22320b62/default_avatar.svg';