diff --git a/app/components/home/HomePageTopBar.tsx b/app/components/home/HomePageTopBar.tsx index cd01f1e..372b4de 100644 --- a/app/components/home/HomePageTopBar.tsx +++ b/app/components/home/HomePageTopBar.tsx @@ -1,103 +1,74 @@ -import { useState, useEffect, useMemo, memo, useCallback } from "react"; +import { memo, useCallback } from "react"; +import { Link } from "@remix-run/react"; +import { Bell, Search, ShoppingBag } from "lucide-react"; import logo from "../../assets/logo/SVG-07.svg"; +import { useCartCount } from "~/requestHandler/use-cart-hooks"; +import { useBadgeCounts } from "~/hooks/useBadgeCounts"; +import { useRootData } from "~/hooks/use-root-data"; const HomePageTopBar = memo(() => { - const [activeTab, setActiveTab] = useState(0); - const tabs = useMemo(() => ["تخفیفها", "برترین فروشگاهها", "برای شما"], []); - - // Scroll to section when tab is clicked - const scrollToSection = useCallback((sectionId: string) => { - const section = document.getElementById(sectionId); - if (section) { - section.scrollIntoView({ behavior: "smooth" }); - } - }, []); - - // Update active tab based on scroll position with throttling - useEffect(() => { - let ticking = false; - const handleScroll = () => { - if (!ticking) { - window.requestAnimationFrame(() => { - const section1 = document.getElementById("section1"); - const section2 = document.getElementById("section2"); - const section3 = document.getElementById("section3"); - - if (section1 && section2 && section3) { - const scrollPosition = window.scrollY; - - if (scrollPosition >= section3.offsetTop - 100) { - setActiveTab(2); - } else if (scrollPosition >= section2.offsetTop - 100) { - setActiveTab(1); - } else { - setActiveTab(0); - } - } - ticking = false; - }); - ticking = true; - } - }; - - window.addEventListener("scroll", handleScroll, { passive: true }); - return () => window.removeEventListener("scroll", handleScroll); - }, []); + const { user } = useRootData(); + const isLoggedIn = !!user?.access_token; + const cartCount = useCartCount(); + const { data: badgeCounts } = useBadgeCounts(); + const accountUnread = + (badgeCounts?.chat || 0) + (badgeCounts?.order_updates || 0); const scrollToTop = useCallback(() => { window.scrollTo({ top: 0, behavior: "smooth" }); }, []); - const handleTabClick = useCallback( - (index: number) => { - setActiveTab(index); - scrollToSection(`section${index + 1}`); - }, - [scrollToSection] - ); - return ( -
- {tab} -
-