fix(theme): show progress bar after delay (#1278)

pull/1279/head
Divyansh Singh 3 years ago committed by GitHub
parent ee37eaa271
commit 496bd34ff4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -28,11 +28,24 @@ const theme: Theme = {
NotFound, NotFound,
enhanceApp: ({ router }) => { enhanceApp: ({ router }) => {
if (inBrowser) { if (inBrowser) {
let timeoutId: NodeJS.Timeout
let called = false
router.onBeforeRouteChange = () => { router.onBeforeRouteChange = () => {
nprogress.start() timeoutId = setTimeout(() => {
nprogress.start()
called = true
}, 500)
} }
router.onAfterRouteChanged = () => { router.onAfterRouteChanged = () => {
nprogress.done(true) if (timeoutId) {
clearTimeout(timeoutId)
}
if (called) {
nprogress.done(true)
called = false
}
} }
} }
} }

@ -13,12 +13,12 @@ export function isExternal(path: string): boolean {
} }
export function throttleAndDebounce(fn: () => void, delay: number): () => void { export function throttleAndDebounce(fn: () => void, delay: number): () => void {
let timeout: any let timeoutId: NodeJS.Timeout
let called = false let called = false
return () => { return () => {
if (timeout) { if (timeoutId) {
clearTimeout(timeout) clearTimeout(timeoutId)
} }
if (!called) { if (!called) {
@ -28,7 +28,7 @@ export function throttleAndDebounce(fn: () => void, delay: number): () => void {
called = false called = false
}, delay) }, delay)
} else { } else {
timeout = setTimeout(fn, delay) timeoutId = setTimeout(fn, delay)
} }
} }
} }

Loading…
Cancel
Save