Files
speckle-server/packages/frontend-2/plugins/preventLeaveOnUpload.client.ts
T
Kristaps Fabians Geikins 7e01c6f769 feat(fe2): improved file import error handling (#5016)
* 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
2025-07-02 11:01:41 +03:00

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 = ''
}
})
})