Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit d004015

Browse files
Alexandre Steinhacdias
Alexandre Stein
authored andcommitted
feat: send message to user if file upload isn't completed and they try to close the tab
1 parent ba5b5fb commit d004015

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/api/files.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ export async function post (url, content = '', overwrite = false, onupload) {
9494
request.upload.onprogress = onupload
9595
}
9696

97+
// Send a message to user before closing the tab during file upload
98+
window.onbeforeunload = () => "Files are being uploaded."
99+
97100
request.onload = () => {
98101
if (request.status === 200) {
99102
resolve(request.responseText)
@@ -109,7 +112,8 @@ export async function post (url, content = '', overwrite = false, onupload) {
109112
}
110113

111114
request.send(content)
112-
})
115+
// Upload is done no more message before closing the tab
116+
}).finally(() => { window.onbeforeunload = null })
113117
}
114118

115119
function moveCopy (items, copy = false) {

0 commit comments

Comments
 (0)