Skip to content

Commit 790f4aa

Browse files
committed
feat: added SmoothScroll without useEffect and fixed breaking changes to ThemeSwitch
1 parent 65e5a73 commit 790f4aa

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

site/src/app/layout.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ export default function RootLayout({
6161
<body suppressHydrationWarning>
6262
<div className={`min-h-screen bg-neutral-100 dark:bg-neutral-950 text-gray-800 dark:text-gray-200`}>
6363
<div className="transition-colors duration-300">
64-
<Navbar />
65-
<Providers> {children} </Providers>
66-
<Footer />
64+
<Providers>
65+
<Navbar />
66+
{children}
67+
<Footer />
68+
</Providers>
6769
</div>
6870
</div>
6971
</body>

site/src/components/Navbar.tsx

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
1-
import useReadingProgress from '@/hooks/useReadingProgress'
1+
'use client'
2+
23
import ThemeSwitch from './ThemeSwitch';
34

45
const Navbar = () => {
5-
const completion = useReadingProgress();
6+
// const completion = useReadingProgress();
67

78
return (
89
<header className="sticky top-0 z-50 py-6 backdrop-blur-xl mx-auto max-w-full px-4 sm:px-12 md:px-16 lg:max-w-5xl xl:max-w-6xl 2xl:max-w-7xl">
9-
<nav className="flex items-center justify-between">
10-
<ul className="flex gap-4 sm:gap-8">
11-
<li><a href="/" className="hover:underline hover:underline-offset-4">home</a></li>
12-
<li><a href="#experience" className="hover:underline hover:underline-offset-4">experience</a></li>
13-
{/* <li><a href="#education" className="hover:underline hover:underline-offset-4">education</a></li> */}
14-
<li><a href="#projects" className="hover:underline hover:underline-offset-4">projects</a></li>
15-
</ul>
16-
<div className="flex gap-0 sm:gap-4">
17-
<ThemeSwitch />
18-
</div>
19-
</nav>
10+
<nav className="flex items-center justify-between">
11+
<ul className="flex gap-4 sm:gap-8" onClick={
12+
(event: React.SyntheticEvent) => {
13+
event.preventDefault();
14+
const target = event.target as HTMLAnchorElement;
15+
const id = target.getAttribute('href');
16+
if (id !== "#") {
17+
const element = document.getElementById(String(id?.replace('#', '')));
18+
const y = element && element.getBoundingClientRect().top + window.scrollY - 100;
19+
if (y !== null) {
20+
window.scrollTo({top: y, behavior: 'smooth'});
21+
} else {
22+
element?.scrollIntoView({
23+
behavior: 'smooth'
24+
});
25+
}
26+
} else {
27+
window.scrollTo({
28+
top: 0,
29+
behavior: 'smooth'
30+
});
31+
}
32+
}
33+
}>
34+
<li><a href="#" className="hover:underline hover:underline-offset-4">home</a></li>
35+
<li><a href="#experience" className="hover:underline hover:underline-offset-4">experience</a></li>
36+
{/* <li><a href="#education" className="hover:underline hover:underline-offset-4">education</a></li> */}
37+
<li><a href="#projects" className="hover:underline hover:underline-offset-4">projects</a></li>
38+
</ul>
39+
<div className="flex gap-0 sm:gap-4">
40+
<ThemeSwitch />
41+
</div>
42+
</nav>
2043
</header>
2144
)
2245
}

0 commit comments

Comments
 (0)