From 304920150486d4b8fbe8ec23aab7ad1fc608ef82 Mon Sep 17 00:00:00 2001 From: sageTheDM Date: Fri, 11 Oct 2024 09:58:51 +0200 Subject: [PATCH] Header comments --- app/components/Header.tsx | 59 ++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/app/components/Header.tsx b/app/components/Header.tsx index e477a80..3d26f4d 100644 --- a/app/components/Header.tsx +++ b/app/components/Header.tsx @@ -1,12 +1,13 @@ import React, { useState, useRef, useEffect } from 'react'; -import Login from './Login'; +import Login from './Login'; // Importing the Login component +// Define the props for the Header component interface HeaderProps { - onViewChange: (view: 'AI' | 'FAQ' | 'Documentation' | 'Credits') => void; - showDivs: boolean; - toggleDivs: () => void; - showHistoryModelsToggle: boolean; - showToggle: boolean; + onViewChange: (view: 'AI' | 'FAQ' | 'Documentation' | 'Credits') => void; // Function to change views + showDivs: boolean; // State to show/hide divs + toggleDivs: () => void; // Function to toggle divs + showHistoryModelsToggle: boolean; // State to show/hide history models + showToggle: boolean; // State to show/hide toggle button } const Header: React.FC = ({ @@ -16,50 +17,53 @@ const Header: React.FC = ({ showHistoryModelsToggle, showToggle, }) => { + // State to manage menu open/closed state const [menuOpen, setMenuOpen] = useState(false); - const dropdownRef = useRef(null); - const toggleRef = useRef(null); + const dropdownRef = useRef(null); // Ref for dropdown menu + const toggleRef = useRef(null); // Ref for hamburger toggle - // Pages that will be displayed in the menu + // Pages to be displayed in the navigation menu const pages: ('AI' | 'FAQ' | 'Documentation' | 'Credits')[] = ['AI', 'FAQ', 'Documentation', 'Credits']; - // Toggle menu state + // Function to toggle the dropdown menu state const toggleMenu = () => { setMenuOpen((prevMenuOpen) => !prevMenuOpen); }; - // Handle button click + // Function to handle view change when a menu item is clicked const handleViewChange = (page: 'AI' | 'FAQ' | 'Documentation' | 'Credits') => { - onViewChange(page); - setMenuOpen(false); // Close the menu when a button is clicked + onViewChange(page); // Call the onViewChange function with the selected page + setMenuOpen(false); // Close the menu after selection }; - // Effect to handle clicks outside of the dropdown + // Effect to handle clicks outside the dropdown to close it useEffect(() => { const handleClickOutside = (event: MouseEvent) => { + // Check if the click is outside the dropdown and toggle elements if ( dropdownRef.current && !dropdownRef.current.contains(event.target as Node) && toggleRef.current && !toggleRef.current.contains(event.target as Node) ) { - setMenuOpen(false); + setMenuOpen(false); // Close the menu if the click is outside } }; - document.addEventListener('mousedown', handleClickOutside); + document.addEventListener('mousedown', handleClickOutside); // Listen for clicks return () => { - document.removeEventListener('mousedown', handleClickOutside); + document.removeEventListener('mousedown', handleClickOutside); // Cleanup listener on unmount }; }, []); return ( <>
+ {/* Show the toggle button for divs if conditions are met */} {showToggle && showHistoryModelsToggle && ( )} + + {/* Navigation menu */} + + {/* Hamburger menu toggle */}
- - - + {/* Top bar of the hamburger */} + {/* Middle bar of the hamburger */} + {/* Bottom bar of the hamburger */}
+
- {/* AI logo or text */} + {/* Placeholder for AI logo or text */}
- + {/* Include the Login component */}
); }; -export default Header; +export default Header; // Exporting the Header component