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

View File

@ -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))
}

View File

@ -121,6 +121,7 @@ export const EditorSwiper = (props: Props) => {
const handleChangeIndex = (direction: 'left' | 'right', index: number) => {
const images = [...props.images]
if (images?.length > 0) {
if (direction === 'left' && index > 0) {
const copy = images.splice(index, 1)[0]
images.splice(index - 1, 0, copy)
@ -133,6 +134,7 @@ export const EditorSwiper = (props: Props) => {
mainSwipeRef.current.swiper.slideTo(direction === 'left' ? index - 1 : index + 1)
}, 0)
}
}
const handleSaveBeforeSlideChange = () => {
handleSlideDescriptionChange(slideIndex(), 'body', slideBody())

View File

@ -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)
}
}