Skip to content

Commit fb9e0b9

Browse files
feat: add loading indicator during page transitions (#119)
* feat: add loading indicator during page transitions * fix: update loading bar color --------- Co-authored-by: satnaing <[email protected]>
1 parent b25de1c commit fb9e0b9

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"react-day-picker": "8.10.1",
4949
"react-dom": "^19.0.0",
5050
"react-hook-form": "^7.54.0",
51+
"react-top-loading-bar": "^3.0.2",
5152
"recharts": "^2.14.1",
5253
"tailwind-merge": "^2.5.5",
5354
"tailwindcss-animate": "^1.0.7",

pnpm-lock.yaml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useEffect, useRef } from 'react'
2+
import { useRouterState } from '@tanstack/react-router'
3+
import LoadingBar, { LoadingBarRef } from 'react-top-loading-bar'
4+
5+
export function NavigationProgress() {
6+
const ref = useRef<LoadingBarRef>(null)
7+
const state = useRouterState()
8+
9+
useEffect(() => {
10+
if (state.status === 'pending') {
11+
ref.current?.continuousStart()
12+
} else {
13+
ref.current?.complete()
14+
}
15+
}, [state.status])
16+
17+
return (
18+
<LoadingBar
19+
color='hsl(var(--muted-foreground))'
20+
ref={ref}
21+
shadow={true}
22+
height={2}
23+
/>
24+
)
25+
}

src/routes/__root.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createRootRouteWithContext, Outlet } from '@tanstack/react-router'
33
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
44
import { TanStackRouterDevtools } from '@tanstack/router-devtools'
55
import { Toaster } from '@/components/ui/toaster'
6+
import { NavigationProgress } from '@/components/navigation-progress'
67
import GeneralError from '@/features/errors/general-error'
78
import NotFoundError from '@/features/errors/not-found-error'
89

@@ -12,6 +13,7 @@ export const Route = createRootRouteWithContext<{
1213
component: () => {
1314
return (
1415
<>
16+
<NavigationProgress />
1517
<Outlet />
1618
<Toaster />
1719
{import.meta.env.MODE === 'development' && (

0 commit comments

Comments
 (0)