Skip to content
Merged
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
9 changes: 2 additions & 7 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@ import {
CardContent,
} from "./ui/card";
import { Button } from "./ui/button";
import { useRef, useContext, useEffect } from "react";
import { useContext } from "react";
import { ThemeContext } from "@/contexts/ThemeContext";

function Navbar() {
const sectionRef=useRef(null);
useEffect(()=>{
sectionRef.current.scrollIntoView({behavior:"smooth"});
},[]);
const currentTheme = useContext(ThemeContext);
if (!currentTheme) return null;
const location = useLocation();

return (
<nav
className={`fixed top-0 left-0 w-full flex flex-col md:flex-row items-center justify-between px-4 py-3 md:px-10 md:py-4 shadow-sm ${currentTheme.theme === "light"
<nav className={`fixed top-0 left-0 w-full flex flex-col md:flex-row items-center justify-between px-4 py-3 md:px-10 md:py-4 shadow-sm ${currentTheme.theme === "light"
? "bg-gradient-to-r from-white to-gray-200 text-gray-600"
: "bg-gray-800 text-gray-200"
} z-50`}
Expand Down
12 changes: 11 additions & 1 deletion src/layouts/MainLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import Navbar from "@/components/Navbar";
import Footer from "@/components/Footer";
import { Outlet } from "react-router-dom";
import { Outlet, useLocation } from "react-router-dom";
import { ThemeProvider } from "@/contexts/ThemeContext";
import { useEffect } from "react";

function ScrollToTop() {
const { pathname } = useLocation();
useEffect(() => {
window.scrollTo({ top: 0, behavior: "smooth" });
}, [pathname]);
return null;
}

function MainLayout() {
return (
<ThemeProvider>
<ScrollToTop />
<Navbar />
<Outlet />
<Footer />
Expand Down