Remove uploading event listeners on ChatInput unmount (#4600)

This commit is contained in:
Max Leiter 2022-06-28 13:31:55 -07:00 committed by GitHub
parent bc709af9fe
commit 80f65c5b72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,12 +11,18 @@ class Uploader {
overlay: HTMLDivElement | null = null; overlay: HTMLDivElement | null = null;
uploadProgressbar: HTMLSpanElement | null = null; uploadProgressbar: HTMLSpanElement | null = null;
onDragEnter = (e: DragEvent) => this.dragEnter(e);
onDragOver = (e: DragEvent) => this.dragOver(e);
onDragLeave = (e: DragEvent) => this.dragLeave(e);
onDrop = (e: DragEvent) => this.drop(e);
onPaste = (e: ClipboardEvent) => this.paste(e);
init() { init() {
document.addEventListener("dragenter", (e) => this.dragEnter(e)); document.addEventListener("dragenter", this.onDragEnter);
document.addEventListener("dragover", (e) => this.dragOver(e)); document.addEventListener("dragover", this.onDragOver);
document.addEventListener("dragleave", (e) => this.dragLeave(e)); document.addEventListener("dragleave", this.onDragLeave);
document.addEventListener("drop", (e) => this.drop(e)); document.addEventListener("drop", this.onDrop);
document.addEventListener("paste", (e) => this.paste(e)); document.addEventListener("paste", this.onPaste);
socket.on("upload:auth", (token) => this.uploadNextFileInQueue(token)); socket.on("upload:auth", (token) => this.uploadNextFileInQueue(token));
} }
@ -302,6 +308,12 @@ class Uploader {
this.xhr.abort(); this.xhr.abort();
this.xhr = null; this.xhr = null;
} }
document.removeEventListener("dragenter", this.onDragEnter);
document.removeEventListener("dragover", this.onDragOver);
document.removeEventListener("dragleave", this.onDragLeave);
document.removeEventListener("drop", this.onDrop);
document.removeEventListener("paste", this.onPaste);
} }
} }