From d004015f0335a4674b4440613086da94de506b7e Mon Sep 17 00:00:00 2001 From: Alexandre Stein Date: Sat, 26 Jan 2019 12:27:58 +0100 Subject: [PATCH] feat: send message to user if file upload isn't completed and they try to close the tab --- src/api/files.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/api/files.js b/src/api/files.js index 971b056e..00d16339 100644 --- a/src/api/files.js +++ b/src/api/files.js @@ -94,6 +94,9 @@ export async function post (url, content = '', overwrite = false, onupload) { request.upload.onprogress = onupload } + // Send a message to user before closing the tab during file upload + window.onbeforeunload = () => "Files are being uploaded." + request.onload = () => { if (request.status === 200) { resolve(request.responseText) @@ -109,7 +112,8 @@ export async function post (url, content = '', overwrite = false, onupload) { } request.send(content) - }) + // Upload is done no more message before closing the tab + }).finally(() => { window.onbeforeunload = null }) } function moveCopy (items, copy = false) {