Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@approximant/next-progress",
"version": "0.1.0",
"name": "@audiu/next-progress",
"version": "0.1.6",
"description": "NProgress component for Next.js app.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -13,7 +13,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/approximant/next-progress.git"
"url": "git+https://github.com/audiu/next-progress.git"
},
"keywords": [
"Nprogress",
Expand All @@ -24,7 +24,8 @@
"author": "Eamon Ma",
"contributors": [
"Eamon Ma",
"Apal Shah"
"Apal Shah",
"Mike Goodfellow"
],
"license": "MIT",
"bugs": {
Expand Down
55 changes: 21 additions & 34 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import * as NProgress from 'nprogress';
import * as PropTypes from 'prop-types';
import * as React from 'react';

interface RouteProps {
shallow: boolean;
}

export interface NextProgressProps {
/**
* The color of the bar.
Expand Down Expand Up @@ -72,7 +76,6 @@ const NextProgress = ({
}: NextProgressProps) => {
let timer: NodeJS.Timeout | null = null;
let debounceTimer: NodeJS.Timeout | null = null;
let isStarted = false;

React.useEffect(() => {
if (options) {
Expand All @@ -90,68 +93,52 @@ const NextProgress = ({

const routeChangeStart = (
_: string,
{
shallow,
}: {
shallow: boolean;
}
cfg: RouteProps
) => {
if (shallow && !showOnShallow) return;
if (cfg?.shallow && !showOnShallow) return;

if (debounceTimer) {
clearTimeout(debounceTimer);
}

debounceTimer = setTimeout(() => {
isStarted = true;
NProgress.set(startPosition);
NProgress.start();

}, debounce);
};

const routeChangeEnd = (
_: string,
{
shallow,
}: {
shallow: boolean;
}
_: string
) => {
if (debounceTimer && !isStarted) {
if (debounceTimer) {
clearTimeout(debounceTimer);
return;
}

if (shallow && !showOnShallow) return;
if (timer) {
clearTimeout(timer);
}

if (timer) clearTimeout(timer);
timer = setTimeout(() => {
isStarted = false;
NProgress.done(true);
}, stopDelayMs);
NProgress.done();
}, stopDelayMs);
};

const routeChangeError = (
_err: Error,
_url: string,
{
shallow,
}: {
shallow: boolean;
}
_url: string
) => {
if (debounceTimer && !isStarted) {
if (debounceTimer) {
clearTimeout(debounceTimer);
return;
}

if (shallow && !showOnShallow) return;
if (timer) {
clearTimeout(timer);
}

if (timer) clearTimeout(timer);
timer = setTimeout(() => {
isStarted = false;
NProgress.done(true);
}, stopDelayMs);
NProgress.done();
}, stopDelayMs);
};

return transformCSS(`
Expand Down