Skip to content

Commit

Permalink
fix(upload): update file in non-default case (#607)
Browse files Browse the repository at this point in the history
* fix(upload): fix upload and remove action of component upload

affects: @gio-design/components

* fix(upload): remove unnessary code

affects: @gio-design/components

* fix(upload): format code

affects: @gio-design/components

* fix(upload): remove unused hook

affects: @gio-design/components

* fix(upload): resolve compile error

affects: @gio-design/components

* refactor(upload): resolve compile error

affects: @gio-design/components

* refactor(upload): remove log

affects: @gio-design/components

* fix(upload): reconstruct code

affects: @gio-design/components

* test(upload): modify upload test

affects: @gio-design/components

* fix(upload): fix the problem that upload cannot trigger

affects: @gio-design/components

* fix(upload): remove semicolon

affects: @gio-design/components

* fix(upload): fix the problem that file do not render in non-standard way

affects: @gio-design/components

* style(upload): remove log

affects: @gio-design/components

* style(upload): format

affects: @gio-design/components

* test(upload): update snapshot

affects: @gio-design/components

Co-authored-by: huqiyao <huqiyao@growingio.com>
Co-authored-by: Jack <panjie@growingio.com>
Co-authored-by: huskylengcb <649569822@qq.com>
  • Loading branch information
4 people authored Dec 16, 2020
1 parent 533118f commit 8663cc0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
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

1 comment on commit 8663cc0

@vercel
Copy link

@vercel vercel bot commented on 8663cc0 Dec 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.