reset input for selecting file on file choosen on CompositionBox

pull/1381/head
Audric Ackermann 4 years ago
parent 380d296bb2
commit 97ff60f3bb
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -71,7 +71,7 @@ interface Props {
stagedAttachments: Array<StagedAttachmentType>;
clearAttachments: () => any;
removeAttachment: (toRemove: AttachmentType) => void;
onChoseAttachments: (newAttachments: FileList) => void;
onChoseAttachments: (newAttachments: Array<File>) => void;
}
interface State {
@ -642,7 +642,15 @@ export class SessionCompositionBox extends React.Component<Props, State> {
private async onChoseAttachment() {
// Build attachments list
const attachmentsFileList = this.fileInput.current?.files;
let attachmentsFileList = null;
// this is terrible, but we have to reset the input value manually.
// otherwise, the user won't be able to select two times the same file for example.
if (this.fileInput.current?.files) {
attachmentsFileList = Array.from(this.fileInput.current.files);
this.fileInput.current.files = null;
this.fileInput.current.value = '';
}
if (!attachmentsFileList || attachmentsFileList.length === 0) {
return;
}

@ -958,7 +958,7 @@ export class SessionConversation extends React.Component<Props, State> {
});
}
private async onChoseAttachments(attachmentsFileList: FileList) {
private async onChoseAttachments(attachmentsFileList: Array<File>) {
if (!attachmentsFileList || attachmentsFileList.length === 0) {
return;
}
@ -1180,7 +1180,7 @@ export class SessionConversation extends React.Component<Props, State> {
e.stopPropagation();
if (e?.dataTransfer?.files && e.dataTransfer.files.length > 0) {
void this.onChoseAttachments(e.dataTransfer.files);
void this.onChoseAttachments(Array.from(e.dataTransfer.files));
e.dataTransfer.clearData();
this.dragCounter = 0;
this.setState({ isDraggingFile: false });

@ -32,7 +32,7 @@ export async function downloadAttachment(attachment: any) {
// FIXME "178" test to remove once this is fixed server side.
if (!res.response || !res.response.data || res.response.data.length === 178) {
if (res.response.data.length === 178) {
if (res?.response?.data?.length === 178) {
window.log.error(
'Data of 178 length corresponds of a 404 returned as 200 by file.getsession.org.'
);

Loading…
Cancel
Save