Skip to content

Commit f9bc029

Browse files
feat: Add a top progress loader when navigating pages
1 parent e837015 commit f9bc029

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"ms": "^2.1.3",
5353
"next": "15.2.3",
5454
"next-themes": "^0.4.4",
55+
"nextjs-toploader": "^3.8.15",
5556
"react": "^19.0.0",
5657
"react-dom": "^19.0.0",
5758
"react-hook-form": "^7.54.2",

pnpm-lock.yaml

Lines changed: 27 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/layout.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import "server-only";
77
import { ThemeProvider } from "@/components/providers";
88
import { Toaster } from "@/components/ui/sonner";
99
import { TooltipProvider } from "@/components/ui/tooltip";
10+
import NextTopLoader from 'nextjs-toploader'
1011
import { SITE_NAME, SITE_DESCRIPTION, SITE_URL } from "@/constants";
1112
import { StartupStudioStickyBanner } from "@/components/startup-studio-sticky-banner";
1213
import { getSessionFromCookie } from "@/utils/auth";
@@ -83,6 +84,11 @@ export default function BaseLayout({
8384
return (
8485
<html lang="en" suppressHydrationWarning>
8586
<body className={inter.className}>
87+
<NextTopLoader
88+
initialPosition={0.15}
89+
shadow="0 0 10px #000, 0 0 5px #000"
90+
height={4}
91+
/>
8692
<Suspense fallback={<ThemeProviderFallback>{children}</ThemeProviderFallback>}>
8793
<SessionProvider>
8894
{children}

src/components/providers.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { useEffect } from "react"
99
import { useConfigStore } from "@/state/config"
1010
import type { getConfig } from "@/flags"
1111
import { EmailVerificationDialog } from "./email-verification-dialog"
12+
import { useTopLoader } from 'nextjs-toploader'
13+
import { usePathname, useRouter, useSearchParams } from "next/navigation"
1214

1315
type Props = {
1416
session: SessionValidationResult
@@ -23,6 +25,23 @@ export function ThemeProvider({
2325
}: React.ComponentProps<typeof NextThemesProvider> & Props) {
2426
const setSession = useSessionStore((store) => store.setSession)
2527
const setConfig = useConfigStore((store) => store.setConfig)
28+
const { start, done } = useTopLoader()
29+
const pathname = usePathname();
30+
const searchParams = useSearchParams();
31+
const router = useRouter();
32+
33+
useEffect(() => {
34+
const _push = router.push.bind(router);
35+
36+
router.push = (href, options) => {
37+
start();
38+
_push(href, options);
39+
};
40+
}, [])
41+
42+
useEffect(() => {
43+
done();
44+
}, [pathname, searchParams]);
2645

2746
useEffect(() => {
2847
setSession(session)

0 commit comments

Comments
 (0)