"use client"; import Image from 'next/image'; import { Home, InfoIcon, MessageCircle, Search, FileQuestion, Menu, X } from 'lucide-react'; import { useTheme } from "next-themes"; import { useEffect, useState } from "react"; import { useMedia } from 'react-use'; import useSWR from 'swr'; import logo from '@/public/smart-retrieval-logo.webp'; import { HeaderNavLink } from '@/app/components/ui/navlink'; import { MobileMenu } from '@/app/components/ui/mobilemenu'; import { IconSpinner } from '@/app/components/ui/icons' const MobileMenuItems = [ { href: '/', icon: , label: 'Home', }, { href: '/about', icon: , label: 'About', }, { href: '/chat', icon: , label: 'Chat', }, { href: '/query', icon: , label: 'Q&A', }, { href: '/search', icon: , label: 'Search', }, ]; export default function Header() { const isLargeScreen = useMedia('(min-width: 1024px)', false); const [mounted, setMounted] = useState(false); const { theme, setTheme } = useTheme(); // Use SWR for API status fetching const healthcheck_api = process.env.NEXT_PUBLIC_HEALTHCHECK_API; const { data, error: apiError, isLoading } = useSWR(healthcheck_api, async (url) => { try { // Fetch the data const response = await fetch(url, { signal: AbortSignal.timeout(5000), // Abort the request if it takes longer than 5 seconds }); if (!response.ok) { throw new Error(response.statusText || 'Unknown Error'); } const data = await response.json(); return data; } catch (error: any) { console.error('Error fetching Backend API Status'); throw error; } }, { revalidateOnFocus: true, // Revalidate when the window gains focus revalidateIfStale: true, // Revalidate if the data is stale refreshInterval: 60000, // Revalidate every 60 seconds }); if (apiError) { if (apiError.name === 'AbortError') { console.error('[Header] Error fetching Backend API Status: Request timed out'); } else { console.error('[Header] Error fetching Backend API Status:', apiError.message); } } useEffect(() => { setMounted(true); }, []); const [isMobileMenuOpen, setMobileMenuOpen] = useState(false); const toggleMobileMenu = () => { // Handle the toggle click here if (isMobileMenuOpen) { // If the menu is open, close it setMobileMenuOpen(false); } else { // If the menu is closed, open it setMobileMenuOpen(true); } }; if (!mounted) return null; return (
{/* Navigation Bar */}
); }