Skip to content

Commit d61c38a

Browse files
fix bug when uploading attachment
1 parent 88d0d80 commit d61c38a

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11

22
export interface IUploadAttachmentState {
3-
file: any;
43
hideDialog: boolean;
54
dialogMessage: string;
65
isLoading: boolean;
7-
6+
87
}

src/controls/listItemAttachments/ListItemAttachments.tsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,22 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
120120
dialogMessage: strings.ListItemAttachmentserrorLoadAttachments.replace('{0}', error.message)
121121
});
122122
});
123-
}
124-
else if(this.state.filesToUpload && this.state.filesToUpload.length > 0){
125-
let files = this.state.filesToUpload.map(file=>({
126-
FileName: file.name,
127-
ServerRelativeUrl: undefined
128-
}));
129-
await this.loadAttachmentsPreview(files);
130-
}
131-
else{
132-
this.setState({
133-
fireUpload: false,
134-
hideDialog: true,
135-
dialogMessage: '',
136-
showPlaceHolder: true
137-
});
138-
}
123+
}
124+
else if(this.state.filesToUpload && this.state.filesToUpload.length > 0){
125+
let files = this.state.filesToUpload.map(file=>({
126+
FileName: file.name,
127+
ServerRelativeUrl: undefined
128+
}));
129+
await this.loadAttachmentsPreview(files);
130+
}
131+
else{
132+
this.setState({
133+
fireUpload: false,
134+
hideDialog: true,
135+
dialogMessage: '',
136+
showPlaceHolder: true
137+
});
138+
}
139139
}
140140

141141
/**
@@ -158,6 +158,10 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
158158
*/
159159
private _onAttachmentUpload = async (file: File) => {
160160
// load Attachments
161+
this.setState({
162+
fireUpload: false,
163+
});
164+
161165
if(!this.state.itemId){
162166
let files = this.state.filesToUpload || [];
163167
files.push(file);

src/controls/listItemAttachments/UploadAttachment.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export class UploadAttachment extends React.Component<IUploadAttachmentProps, IU
1717
super(props);
1818

1919
this.state = {
20-
file: null,
2120
hideDialog: true,
2221
dialogMessage: '',
2322
isLoading: false,
@@ -35,7 +34,7 @@ export class UploadAttachment extends React.Component<IUploadAttachmentProps, IU
3534
* @param prevState
3635
*/
3736
public componentDidUpdate(prevProps: IUploadAttachmentProps, prevState: IUploadAttachmentState): void {
38-
if (this.props.fireUpload) {
37+
if (this.props.fireUpload && !this.state.isLoading) {
3938
this.fileInput.current.value = '';
4039
this.fileInput.current.click();
4140
}
@@ -62,19 +61,16 @@ export class UploadAttachment extends React.Component<IUploadAttachmentProps, IU
6261
const file = e.target.files[0];
6362
return new Promise<void>((resolve,errorCallback)=>{
6463
reader.onloadend = async () => {
65-
this.setState({
66-
file: file
67-
});
68-
64+
6965
try {
7066
if(this.props.itemId && this.props.itemId > 0){
7167
await this._spservice.addAttachment(this.props.listId, this.props.itemId, file.name, file, this.props.webUrl);
7268
}
73-
69+
70+
this.props.onAttachmentUpload(file);
7471
this.setState({
7572
isLoading: false
7673
});
77-
this.props.onAttachmentUpload(file);
7874
resolve();
7975
} catch (error) {
8076
this.setState({
@@ -87,7 +83,7 @@ export class UploadAttachment extends React.Component<IUploadAttachmentProps, IU
8783
};
8884
reader.readAsDataURL(file);
8985
});
90-
86+
9187
}
9288

9389
/**

0 commit comments

Comments
 (0)