fix: sync Upload UI with editImageFiles in NewApiPage (#11653)

Resolved issue where Upload component UI was not synchronized with
editImageFiles state in NewApiPage. Switched to controlled fileList and
handled file removal via onRemove to ensure consistent UI updates.
This commit is contained in:
Xiang, Haihao 2025-12-08 11:09:18 +08:00 committed by GitHub
parent 82ec18c0fb
commit 1a737f5137
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,6 +31,8 @@ import { getErrorMessage, uuid } from '@renderer/utils'
import { isNewApiProvider } from '@renderer/utils/provider'
import { Avatar, Button, Empty, InputNumber, Segmented, Select, Upload } from 'antd'
import TextArea from 'antd/es/input/TextArea'
import type { RcFile } from 'antd/es/upload'
import type { UploadFile } from 'antd/es/upload/interface'
import type { FC } from 'react'
import React from 'react'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
@ -553,7 +555,31 @@ const NewApiPage: FC<{ Options: string[] }> = ({ Options }) => {
maxCount={16}
showUploadList={true}
listType="picture"
beforeUpload={handleImageUpload}>
beforeUpload={handleImageUpload}
fileList={editImageFiles.map((file, idx): UploadFile<any> => {
const rcFile: RcFile = {
...file,
uid: String(idx),
lastModifiedDate: file.lastModified ? new Date(file.lastModified) : new Date()
}
return {
uid: rcFile.uid,
name: rcFile.name || `image_${idx + 1}.png`,
status: 'done',
url: URL.createObjectURL(file),
originFileObj: rcFile,
lastModifiedDate: rcFile.lastModifiedDate
}
})}
onRemove={(file) => {
setEditImageFiles((prev) =>
prev.filter((f) => {
const idx = prev.indexOf(f)
return String(idx) !== file.uid
})
)
return true
}}>
<ImagePlaceholder>
<ImageSizeImage src={IcImageUp} theme={theme} />
</ImagePlaceholder>