Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(upload): update file in non-default case #607

Merged
merged 21 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/components/src/components/upload/Upload.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useRef } from 'react';
import React, { useState, useRef, useEffect } from 'react';
import RcUpload from 'rc-upload';
import classnames from 'classnames';
import usePrefixCls from '../../utils/hooks/use-prefix-cls';
Expand Down Expand Up @@ -55,6 +55,10 @@ const Upload: React.FC<IUploadProps> = ({
...restProps
}: IUploadProps) => {
const [file, setFile] = useState<IUploadFile>(getEmptyFileObj(uploadedFile));
useEffect(() => {
setFile(getEmptyFileObj(uploadedFile));
}, [uploadedFile]);

const rcUploadRef = useRef(null);
const prefixCls = usePrefixCls('upload', customPrefixCls);

Expand All @@ -64,7 +68,6 @@ const Upload: React.FC<IUploadProps> = ({
[`${prefixCls}--success`]: file?.status === STATUS_SUCCESS && !successBorder,
[`${prefixCls}--success-border`]: file?.status === STATUS_SUCCESS && successBorder,
});

const Trigger = triggerMap[type];

const handleBeforeUpload = (fileBeforeUpload: IRcFile, fileList: IRcFile[]) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/upload/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getEmptyFileObj = (file?: IUploadFile): IUploadFile => ({
size: file?.size ?? 0,
name: file?.name ?? '本地上传',
type: file?.type ?? '$empty-file',
status: file?.dataUrl ? STATUS_SUCCESS : STATUS_NOT_YET,
status: file?.dataUrl && file?.status === STATUS_SUCCESS ? STATUS_SUCCESS : STATUS_NOT_YET,
dataUrl: file?.dataUrl ?? '',
});

Expand Down