fix: prompt before closing window

pull/1030/head
Ramires Viana 2020-07-13 18:09:01 +00:00
parent b3b644527d
commit 194030fcfc
2 changed files with 8 additions and 5 deletions

View File

@ -94,9 +94,6 @@ export async function post (url, content = '', overwrite = false, onupload) {
request.upload.onprogress = 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 = () => { request.onload = () => {
if (request.status === 200) { if (request.status === 200) {
resolve(request.responseText) resolve(request.responseText)
@ -112,8 +109,7 @@ export async function post (url, content = '', overwrite = false, onupload) {
} }
request.send(content) request.send(content)
// Upload is done no more message before closing the tab })
}).finally(() => { window.onbeforeunload = null })
} }
function moveCopy (items, copy = false) { function moveCopy (items, copy = false) {

View File

@ -37,6 +37,11 @@ const mutations = {
} }
} }
const beforeUnload = (event) => {
event.preventDefault()
event.returnValue = ''
}
const actions = { const actions = {
upload: (context, item) => { upload: (context, item) => {
let uploadsCount = Object.keys(context.state.uploads).length; let uploadsCount = Object.keys(context.state.uploads).length;
@ -45,6 +50,7 @@ const actions = {
let isUploadsEmpty = uploadsCount == 0 let isUploadsEmpty = uploadsCount == 0
if (isQueueEmpty && isUploadsEmpty) { if (isQueueEmpty && isUploadsEmpty) {
window.addEventListener('beforeunload', beforeUnload)
buttons.loading('upload') buttons.loading('upload')
} }
@ -67,6 +73,7 @@ const actions = {
let canProcess = isBellowLimit && !isQueueEmpty let canProcess = isBellowLimit && !isQueueEmpty
if (isFinished) { if (isFinished) {
window.removeEventListener('beforeunload', beforeUnload)
buttons.success('upload') buttons.success('upload')
context.commit('reset') context.commit('reset')
context.commit('setReload', true, { root: true }) context.commit('setReload', true, { root: true })