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
3 changes: 2 additions & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ScrollToTop from "./components/ScrollToTop";
import React, { useState, useEffect } from "react";
import Navbar from "./components/Navbar/Navbar";
import { Routes, Route } from "react-router-dom";
Expand All @@ -19,7 +20,6 @@ import Chatbot from "./components/Chatbot/Chatbot";
import ContactPage from "./pages/Contactpage";
import { Toaster } from "react-hot-toast";
import LoadingAnimation from "./components/LoadingAnimation";
import ScrollToTop from "../utility/ScrollToTop";
import "./components/FoodDetail/print.css";
import NotFound from "./pages/Notfound";
import StoreContextProvider from "./components/context/StoreContext";
Expand Down Expand Up @@ -121,6 +121,7 @@ const App = () => {
{/* </Footer> */}

<Chatbot /> {/* AI Food Assistant */}

</div>
</StoreContextProvider>
</ThemeContextProvider>
Expand Down
34 changes: 34 additions & 0 deletions frontend/src/components/ScrollToTop.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// frontend/src/components/ScrollToTop.jsx
import { useEffect, useState } from "react";

export default function ScrollToTop() {
const [isVisible, setIsVisible] = useState(false);

useEffect(() => {
const handleScroll = () => {
setIsVisible(window.scrollY > 100);
};
window.addEventListener("scroll", handleScroll);
// initial check
handleScroll();
return () => window.removeEventListener("scroll", handleScroll);
}, []);

const scrollToTop = () => {
window.scrollTo({ top: 0, behavior: "smooth" });
};

return (
isVisible && (
<button
onClick={scrollToTop}
aria-label="Scroll to top"
title="Scroll to top"
className="fixed bottom-6 right-6 p-3 rounded-full bg-blue-600 text-white shadow-lg hover:bg-blue-700 transition-opacity"
style={{ zIndex: 9999 }}
>
⬆
</button>
)
);
}