diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx index d792c30..f47a57a 100644 --- a/src/pages/Index.tsx +++ b/src/pages/Index.tsx @@ -10,31 +10,25 @@ import Fuse from 'fuse.js'; // Animated counter hook function useAnimatedCounter(end: number, duration: number = 2000) { const [count, setCount] = useState(0); - useEffect(() => { let startTime: number; let animationFrame: number; - const animate = (timestamp: number) => { if (!startTime) startTime = timestamp; const progress = Math.min((timestamp - startTime) / duration, 1); - + // Easing function for smooth animation const easeOutQuart = 1 - Math.pow(1 - progress, 4); setCount(Math.floor(easeOutQuart * end)); - if (progress < 1) { animationFrame = requestAnimationFrame(animate); } }; - animationFrame = requestAnimationFrame(animate); return () => cancelAnimationFrame(animationFrame); }, [end, duration]); - return count; } - const Index = () => { const [selectedCategory, setSelectedCategory] = useState(null); const [searchQuery, setSearchQuery] = useState(''); @@ -43,18 +37,23 @@ const Index = () => { const productsCount = useAnimatedCounter(1000, 2000); const clientsCount = useAnimatedCounter(500, 2000); const hoursCount = useAnimatedCounter(24, 1500); - const fuse = useMemo(() => new Fuse(products, { - keys: [ - { name: 'name', weight: 0.4 }, - { name: 'tags', weight: 0.3 }, - { name: 'description', weight: 0.2 }, - { name: 'sku', weight: 0.1 }, - ], + keys: [{ + name: 'name', + weight: 0.4 + }, { + name: 'tags', + weight: 0.3 + }, { + name: 'description', + weight: 0.2 + }, { + name: 'sku', + weight: 0.1 + }], threshold: 0.4, - includeScore: true, + includeScore: true }), []); - const displayProducts = useMemo(() => { let filtered = products; @@ -68,29 +67,24 @@ const Index = () => { if (selectedCategory) { filtered = filtered.filter(p => p.category === selectedCategory); } - return filtered; }, [searchQuery, selectedCategory, fuse]); - - return ( -
+ return
{/* Hero Section */} -
+
-

- Industrial Supplies for - Mining & Construction -

+

Quality fasteners, tools, and equipment. Request a quote today.

{/* Quick Stats with Animated Numbers */} -
+

{productsCount.toLocaleString()}+

Products

@@ -115,32 +109,21 @@ const Index = () => {
{/* Category Sidebar - Sticky */}
- +
{/* Products Section */}
{/* Search Bar - Above Products */}
- +
{/* Products Header */}

- {selectedCategory - ? `${selectedCategory.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase())}` - : searchQuery.length >= 2 - ? `Results for "${searchQuery}"` - : 'Featured Products'} + {selectedCategory ? `${selectedCategory.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase())}` : searchQuery.length >= 2 ? `Results for "${searchQuery}"` : 'Featured Products'}

{displayProducts.length} products available @@ -151,19 +134,15 @@ const Index = () => { {/* Scrollable Products Grid */}

- {displayProducts.map((product) => ( - - ))} + {displayProducts.map(product => )}
- {displayProducts.length === 0 && ( -
+ {displayProducts.length === 0 &&

No products found.

Try different keywords or browse categories.

-
- )} +
}
@@ -180,23 +159,15 @@ const Index = () => { Add items to your cart and request a personalized quote today.

-
- ); +
; }; - -export default Index; +export default Index; \ No newline at end of file