Skip to content

Commit

Permalink
fix: prompt before closing window
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiresviana committed Jul 14, 2020
1 parent b3b6445 commit 194030f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 1 addition & 5 deletions frontend/src/api/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ 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)
Expand All @@ -112,8 +109,7 @@ 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) {
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/store/modules/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const mutations = {
}
}

const beforeUnload = (event) => {
event.preventDefault()
event.returnValue = ''
}

const actions = {
upload: (context, item) => {
let uploadsCount = Object.keys(context.state.uploads).length;
Expand All @@ -45,6 +50,7 @@ const actions = {
let isUploadsEmpty = uploadsCount == 0

if (isQueueEmpty && isUploadsEmpty) {
window.addEventListener('beforeunload', beforeUnload)
buttons.loading('upload')
}

Expand All @@ -67,6 +73,7 @@ const actions = {
let canProcess = isBellowLimit && !isQueueEmpty

if (isFinished) {
window.removeEventListener('beforeunload', beforeUnload)
buttons.success('upload')
context.commit('reset')
context.commit('setReload', true, { root: true })
Expand Down

0 comments on commit 194030f

Please sign in to comment.