Merge pull request #3514 from tylershuster/drag-and-drop

chat: fixes drag-and-drop bugs
This commit is contained in:
matildepark 2020-09-18 14:38:05 -04:00 committed by GitHub
commit d3e4a30a70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -79,7 +79,7 @@ export class ChatScreen extends Component<ChatScreenProps, ChatScreenState> {
}
onDragEnter(event) {
if (!this.readyToUpload() || !event.dataTransfer.files.length) {
if (!this.readyToUpload() || (!event.dataTransfer.files.length && !event.dataTransfer.types.includes('Files'))) {
return;
}
this.setState({ dragover: true });
@ -149,7 +149,12 @@ export class ChatScreen extends Component<ChatScreenProps, ChatScreenState> {
this.setState({ dragover: true });
}
}}
onDragLeave={() => this.setState({ dragover: false })}
onDragLeave={(event) => {
const over = document.elementFromPoint(event.clientX, event.clientY);
if (!over || !event.currentTarget.contains(over)) {
this.setState({ dragover: false });
}}
}
onDrop={this.onDrop.bind(this)}
>
{this.state.dragover ? <SubmitDragger /> : null}

View File

@ -160,10 +160,14 @@ export default class ChatInput extends Component<ChatInputProps, ChatInputState>
if (!this.readyToUpload()) {
return;
}
if (!this.s3Uploader.current || !this.s3Uploader.current.inputRef.current) return;
this.s3Uploader.current.inputRef.current.files = files;
setTimeout(() => {
if (this.s3Uploader.current.state.isUploading) return;
const fire = document.createEvent("HTMLEvents");
fire.initEvent("change", true, true);
this.s3Uploader.current?.inputRef.current?.dispatchEvent(fire);
}, 200);
}
render() {