Skip to content

Commit e113a16

Browse files
committed
fix: sync Upload UI with editImageFiles in NewApiPage
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.
1 parent fb45d94 commit e113a16

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/renderer/src/pages/paintings/NewApiPage.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import { getErrorMessage, uuid } from '@renderer/utils'
3131
import { isNewApiProvider } from '@renderer/utils/provider'
3232
import { Avatar, Button, Empty, InputNumber, Segmented, Select, Upload } from 'antd'
3333
import TextArea from 'antd/es/input/TextArea'
34+
import type { RcFile } from 'antd/es/upload'
35+
import type { UploadFile } from 'antd/es/upload/interface'
3436
import type { FC } from 'react'
3537
import React from 'react'
3638
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
@@ -553,7 +555,31 @@ const NewApiPage: FC<{ Options: string[] }> = ({ Options }) => {
553555
maxCount={16}
554556
showUploadList={true}
555557
listType="picture"
556-
beforeUpload={handleImageUpload}>
558+
beforeUpload={handleImageUpload}
559+
fileList={editImageFiles.map((file, idx): UploadFile<any> => {
560+
const rcFile: RcFile = {
561+
...file,
562+
uid: String(idx),
563+
lastModifiedDate: file.lastModified ? new Date(file.lastModified) : new Date()
564+
}
565+
return {
566+
uid: rcFile.uid,
567+
name: rcFile.name || `image_${idx + 1}.png`,
568+
status: 'done',
569+
url: URL.createObjectURL(file),
570+
originFileObj: rcFile,
571+
lastModifiedDate: rcFile.lastModifiedDate
572+
}
573+
})}
574+
onRemove={(file) => {
575+
setEditImageFiles((prev) =>
576+
prev.filter((f) => {
577+
const idx = prev.indexOf(f)
578+
return String(idx) !== file.uid
579+
})
580+
)
581+
return true
582+
}}>
557583
<ImagePlaceholder>
558584
<ImageSizeImage src={IcImageUp} theme={theme} />
559585
</ImagePlaceholder>

0 commit comments

Comments
 (0)