mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-27 12:51:26 +08:00
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:
parent
82ec18c0fb
commit
1a737f5137
@ -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>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user