Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Apr 29, 2022
1 parent 285e830 commit 5746f95
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions packages/docusaurus-theme-classic/src/nprogress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@

import nprogress from 'nprogress';
import './nprogress.css';
import type {Location} from 'history';
import type {ClientModule} from '@docusaurus/types';

nprogress.configure({showSpinner: false});

const delay = 200;

export function onRouteUpdate({
location,
previousLocation,
}: {
location: Location;
previousLocation: Location | null;
}): (() => void) | undefined {
if (location.pathname !== previousLocation?.pathname) {
const progressBarTimeout = window.setTimeout(() => {
nprogress.start();
}, delay);
return () => window.clearTimeout(progressBarTimeout);
}
return undefined;
}
const clientModule: ClientModule = {
onRouteUpdate({location, previousLocation}) {
if (location.pathname !== previousLocation?.pathname) {
const progressBarTimeout = window.setTimeout(() => {
nprogress.start();
}, delay);
return () => window.clearTimeout(progressBarTimeout);
}
return undefined;
},
onRouteDidUpdate() {
nprogress.done();
},
};

export function onRouteDidUpdate(): void {
nprogress.done();
}
export default clientModule;

0 comments on commit 5746f95

Please sign in to comment.