MCPcopy Create free account
hub / github.com/Bitbox-Connect/Bitbox / Navbar

Function Navbar

client/src/component/Navbar.jsx:14–485  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

12import axios from "axios";
13
14function Navbar(props) {
15 const { showAlert, mode } = props;
16 const navigate = useNavigate();
17 const location = useLocation();
18
19 const { currentUser, userLoggedIn, setUserLoggedIn } = useAuth();
20 // eslint-disable-next-line
21 const [isScrolled, setIsScrolled] = useState(false); // State to keep track of whether page has been scrolled
22
23 // eslint-disable-next-line
24 const [isOpen, setIsOpen] = useState(false);
25 // State to control the sidebar visibility
26 const [isSidebarOpen, setIsSidebarOpen] = useState(false);
27
28 const toggleSidebar = (e) => {
29 e.preventDefault();
30 setIsSidebarOpen((prev) => !prev);
31 document.body.classList.toggle("no-scroll", !isSidebarOpen);
32 };
33
34 const style = { color: "white", fontSize: "1.5em" };
35
36 useEffect(() => {
37 const handleResize = () => {
38 if (window.innerWidth > 1280) {
39 // Adjust for your breakpoint
40 setIsSidebarOpen(false);
41 document.body.classList.remove("no-scroll");
42 }
43 };
44
45 window.addEventListener("resize", handleResize);
46 return () => window.removeEventListener("resize", handleResize);
47 }, []);
48
49 useEffect(() => {
50 window.onscroll = function () {
51 myFunction();
52 };
53
54 const navbar = document.getElementById("navbar");
55 const sticky = navbar.offsetTop;
56
57 function myFunction() {
58 if (window.pageYOffset >= sticky) {
59 setIsScrolled(true);
60 navbar.classList.add("sticky");
61 } else {
62 setIsScrolled(false);
63 navbar.classList.remove("sticky");
64 }
65 }
66
67 if (window.pageYOffset >= sticky) {
68 setIsScrolled(true);
69 navbar.classList.add("sticky");
70 }
71

Callers

nothing calls this directly

Calls 4

useAuthFunction · 0.90
myFunctionFunction · 0.85
getUserDataFunction · 0.85
renderUploadButtonFunction · 0.85

Tested by

no test coverage detected