diff --git a/src/components/Editor/AudioUploader/AudioUploader.tsx b/src/components/Editor/AudioUploader/AudioUploader.tsx index b5cc4954..de7f2778 100644 --- a/src/components/Editor/AudioUploader/AudioUploader.tsx +++ b/src/components/Editor/AudioUploader/AudioUploader.tsx @@ -34,12 +34,14 @@ export const AudioUploader = (props: Props) => { const handleChangeIndex = (direction: 'up' | 'down', index: number) => { const media = [...props.audio] - if (direction === 'up' && index > 0) { - const copy = media.splice(index, 1)[0] - media.splice(index - 1, 0, copy) - } else if (direction === 'down' && index < media.length - 1) { - const copy = media.splice(index, 1)[0] - media.splice(index + 1, 0, copy) + if (media?.length > 0) { + if (direction === 'up' && index > 0) { + const copy = media.splice(index, 1)[0] + media.splice(index - 1, 0, copy) + } else if (direction === 'down' && index < media.length - 1) { + const copy = media.splice(index, 1)[0] + media.splice(index + 1, 0, copy) + } } props.onAudioSorted(media) } diff --git a/src/components/Views/EditView/EditView.tsx b/src/components/Views/EditView/EditView.tsx index 173d1331..b44c8269 100644 --- a/src/components/Views/EditView/EditView.tsx +++ b/src/components/Views/EditView/EditView.tsx @@ -146,7 +146,7 @@ export const EditView = (props: Props) => { const handleMediaDelete = (index) => { const copy = [...mediaItems()] - copy.splice(index, 1) + if (copy?.length > 0) copy.splice(index, 1) handleInputChange('media', JSON.stringify(copy)) } diff --git a/src/components/_shared/SolidSwiper/EditorSwiper.tsx b/src/components/_shared/SolidSwiper/EditorSwiper.tsx index ba116956..05553e54 100644 --- a/src/components/_shared/SolidSwiper/EditorSwiper.tsx +++ b/src/components/_shared/SolidSwiper/EditorSwiper.tsx @@ -121,17 +121,19 @@ export const EditorSwiper = (props: Props) => { const handleChangeIndex = (direction: 'left' | 'right', index: number) => { const images = [...props.images] - if (direction === 'left' && index > 0) { - const copy = images.splice(index, 1)[0] - images.splice(index - 1, 0, copy) - } else if (direction === 'right' && index < images.length - 1) { - const copy = images.splice(index, 1)[0] - images.splice(index + 1, 0, copy) + if (images?.length > 0) { + if (direction === 'left' && index > 0) { + const copy = images.splice(index, 1)[0] + images.splice(index - 1, 0, copy) + } else if (direction === 'right' && index < images.length - 1) { + const copy = images.splice(index, 1)[0] + images.splice(index + 1, 0, copy) + } + props.onImagesSorted(images) + setTimeout(() => { + mainSwipeRef.current.swiper.slideTo(direction === 'left' ? index - 1 : index + 1) + }, 0) } - props.onImagesSorted(images) - setTimeout(() => { - mainSwipeRef.current.swiper.slideTo(direction === 'left' ? index - 1 : index + 1) - }, 0) } const handleSaveBeforeSlideChange = () => { diff --git a/src/context/meta.tsx b/src/context/meta.tsx index bf2e1a1d..461df35b 100644 --- a/src/context/meta.tsx +++ b/src/context/meta.tsx @@ -184,7 +184,7 @@ function initServerProvider() { const index = tags.findIndex( (prev) => prev.tag === tagDesc.tag && getTagKey(prev, properties) === tagDescKey, ) - if (index !== -1) { + if (index !== -1 && tags?.length > 0) { tags.splice(index, 1) } }