splice-stab-patch

This commit is contained in:
Untone 2024-06-02 13:37:54 +03:00
parent b9705ab8ba
commit 2a80dce98a
4 changed files with 22 additions and 18 deletions

View File

@ -34,12 +34,14 @@ export const AudioUploader = (props: Props) => {
const handleChangeIndex = (direction: 'up' | 'down', index: number) => { const handleChangeIndex = (direction: 'up' | 'down', index: number) => {
const media = [...props.audio] const media = [...props.audio]
if (direction === 'up' && index > 0) { if (media?.length > 0) {
const copy = media.splice(index, 1)[0] if (direction === 'up' && index > 0) {
media.splice(index - 1, 0, copy) const copy = media.splice(index, 1)[0]
} else if (direction === 'down' && index < media.length - 1) { media.splice(index - 1, 0, copy)
const copy = media.splice(index, 1)[0] } else if (direction === 'down' && index < media.length - 1) {
media.splice(index + 1, 0, copy) const copy = media.splice(index, 1)[0]
media.splice(index + 1, 0, copy)
}
} }
props.onAudioSorted(media) props.onAudioSorted(media)
} }

View File

@ -146,7 +146,7 @@ export const EditView = (props: Props) => {
const handleMediaDelete = (index) => { const handleMediaDelete = (index) => {
const copy = [...mediaItems()] const copy = [...mediaItems()]
copy.splice(index, 1) if (copy?.length > 0) copy.splice(index, 1)
handleInputChange('media', JSON.stringify(copy)) handleInputChange('media', JSON.stringify(copy))
} }

View File

@ -121,17 +121,19 @@ export const EditorSwiper = (props: Props) => {
const handleChangeIndex = (direction: 'left' | 'right', index: number) => { const handleChangeIndex = (direction: 'left' | 'right', index: number) => {
const images = [...props.images] const images = [...props.images]
if (direction === 'left' && index > 0) { if (images?.length > 0) {
const copy = images.splice(index, 1)[0] if (direction === 'left' && index > 0) {
images.splice(index - 1, 0, copy) const copy = images.splice(index, 1)[0]
} else if (direction === 'right' && index < images.length - 1) { images.splice(index - 1, 0, copy)
const copy = images.splice(index, 1)[0] } else if (direction === 'right' && index < images.length - 1) {
images.splice(index + 1, 0, copy) 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 = () => { const handleSaveBeforeSlideChange = () => {

View File

@ -184,7 +184,7 @@ function initServerProvider() {
const index = tags.findIndex( const index = tags.findIndex(
(prev) => prev.tag === tagDesc.tag && getTagKey(prev, properties) === tagDescKey, (prev) => prev.tag === tagDesc.tag && getTagKey(prev, properties) === tagDescKey,
) )
if (index !== -1) { if (index !== -1 && tags?.length > 0) {
tags.splice(index, 1) tags.splice(index, 1)
} }
} }