Files
speckle-server/packages/frontend-2/plugins/021-url.ts
T
Kristaps Fabians Geikins 0f5096fb2e feat: copy link to view + load original version (#5202)
* frontend nearly there

* backend adjustment sort of there

* WIP url busted issue

* does it work?

* how about now

* loading seems to work now
2025-08-11 16:02:35 +03:00

44 lines
1007 B
TypeScript

import { until } from '@vueuse/core'
/**
* Global state for if vue-router is in a pending navigation
* (helps avoid race conditions in environments w/ many concurrent navigations like the viewer)
*/
export default defineNuxtPlugin(() => {
const router = useRouter()
const route = useRoute()
const logger = useLogger()
const isNavigating = ref(false)
// Only drive on client
if (import.meta.client) {
router.beforeEach(() => {
isNavigating.value = true
})
router.afterEach(async (to) => {
const newPath = to.fullPath
try {
await until(() => route.fullPath === newPath).toBeTruthy({
timeout: 500,
throwOnTimeout: true
})
} catch (e) {
logger.warn(e, 'Waiting for navigation to finalize failed')
}
isNavigating.value = false
})
router.onError(() => {
isNavigating.value = false
})
}
return {
provide: {
isNavigating: computed(() => isNavigating.value)
}
}
})