7e01c6f769
* WIP error dialog * import error reporting * dialog content memoization * dialog work * more cleanup * apollo cache adjustments * add jobId to uploads table * fix showing old pending version state * feat(fe2): prevent user from leaving page if active uploads (#5017) * feat(fe2): prevent user leaving if active uploads * fixxes
35 lines
928 B
TypeScript
35 lines
928 B
TypeScript
import { useGlobalFileImportManager } from '~/lib/core/composables/fileImport'
|
|
|
|
export default defineNuxtPlugin(() => {
|
|
const { hasActiveUploads, unregisterAllActiveUploads } = useGlobalFileImportManager()
|
|
const router = useRouter()
|
|
|
|
// Handle nuxt navigation
|
|
router.beforeEach((to, from, next) => {
|
|
// Ignore if same route
|
|
if (to.fullPath === from.fullPath) return next()
|
|
|
|
if (hasActiveUploads.value) {
|
|
// eslint-disable-next-line no-alert
|
|
const confirmLeave = window.confirm(
|
|
'An upload is in progress. Are you sure you want to leave?'
|
|
)
|
|
|
|
if (confirmLeave) {
|
|
unregisterAllActiveUploads()
|
|
} else {
|
|
return next(false)
|
|
}
|
|
}
|
|
next()
|
|
})
|
|
|
|
// Handle the user trying to close the tab or browser
|
|
window.addEventListener('beforeunload', (e) => {
|
|
if (hasActiveUploads.value) {
|
|
e.preventDefault()
|
|
e.returnValue = ''
|
|
}
|
|
})
|
|
})
|