Spaces:
Running
Running
File size: 13,150 Bytes
b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e 1684141 b89a86e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
import { useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { productsApi, categoriesApi, storesApi } from "@/lib/api";
import logoUrl from "@assets/assets_task_01k3qp9hccec89tp5ht8ee88x5_1756363038_img_1-removebg-preview (1)_1756364677577.png";
import Header from "@/components/layout/header";
import CategoryNav from "@/components/category/category-nav";
import ProductGrid from "@/components/product/product-grid";
import StoreCard from "@/components/store/store-card";
import { Button } from "@/components/ui/button";
import { Skeleton } from "@/components/ui/skeleton";
import { Category, Product, Store } from "@/types";
import { Package, ShieldCheck, Star, Truck, CreditCard, HeadphonesIcon } from "lucide-react";
import { LoadingSpinner } from "@/components/ui/spinner";
export default function Home() {
const [searchQuery, setSearchQuery] = useState("");
const [selectedCategory, setSelectedCategory] = useState<string>("");
const { data: categories = [], isLoading: categoriesLoading } = useQuery({
queryKey: ['/api/categories'],
queryFn: () => categoriesApi.getAll(),
});
const { data: featuredProducts = [], isLoading: featuredLoading } = useQuery({
queryKey: ['/api/products/featured'],
queryFn: () => productsApi.getFeatured(),
});
const { data: stores = [], isLoading: storesLoading } = useQuery({
queryKey: ['/api/stores'],
queryFn: () => storesApi.getAll(),
});
const { data: searchResults = [], isLoading: searchLoading } = useQuery({
queryKey: ['/api/products', { search: searchQuery, category: selectedCategory }],
queryFn: () => productsApi.getAll({
...(searchQuery && { search: searchQuery }),
...(selectedCategory && { category: selectedCategory })
}),
enabled: !!(searchQuery || selectedCategory),
});
const showingResults = searchQuery || selectedCategory;
const displayProducts = showingResults ? searchResults : featuredProducts;
const isProductsLoading = showingResults ? searchLoading : featuredLoading;
return (
<div className="min-h-screen bg-gradient-to-br from-orange-100/40 via-amber-100/30 to-red-100/40">
<Header searchQuery={searchQuery} setSearchQuery={setSearchQuery} />
{/* Hero Section - Enhanced Modern Style */}
<section className="py-4 px-2" data-testid="hero-section">
<div className="max-w-full mx-auto px-2">
{/* Hero Banner Card - Enhanced */}
<div className="bg-gradient-to-r from-orange-500 to-red-600 rounded-3xl p-4 sm:p-6 mb-4 shadow-xl text-white relative overflow-hidden">
{/* Background pattern */}
<div className="absolute inset-0 opacity-10">
<div className="absolute top-0 right-0 w-96 h-96 bg-white rounded-full -translate-y-48 translate-x-48"></div>
<div className="absolute bottom-0 left-0 w-64 h-64 bg-white rounded-full translate-y-32 -translate-x-32"></div>
</div>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8 items-center relative z-10">
<div>
<div className="flex items-center mb-6" data-testid="hero-title">
<img
src={logoUrl}
alt="Shoposphere"
className="h-16 w-auto mr-6 drop-shadow-lg"
/>
<div>
<h1 className="text-4xl lg:text-5xl font-bold mb-2">
Discover Amazing Products
</h1>
<p className="text-xl opacity-90">from trusted sellers worldwide</p>
</div>
</div>
<div className="flex flex-col sm:flex-row gap-4">
<Button className="bg-gradient-to-r from-orange-500 to-red-500 text-white hover:from-orange-600 hover:to-red-600 rounded-xl px-8 py-4 text-lg font-semibold shadow-lg hover:shadow-xl transition-all duration-300 hover:scale-105" data-testid="browse-products">
Start Shopping
</Button>
<Button variant="outline" className="border-2 border-white/80 text-white hover:bg-white hover:text-black backdrop-blur-sm rounded-xl px-8 py-4 text-lg font-semibold shadow-lg hover:shadow-xl transition-all duration-300 hover:scale-105" data-testid="view-stores">
Learn more
</Button>
</div>
</div>
<div className="hidden lg:block">
<div className="bg-gradient-to-br from-orange-100 to-red-100 rounded-3xl p-8 text-center">
<Package className="h-16 w-16 mx-auto mb-4 text-orange-500" />
<h3 className="text-xl font-semibold text-gray-800 mb-2">Fast Delivery</h3>
<p className="text-gray-600">Get your orders delivered quickly</p>
</div>
</div>
</div>
</div>
</div>
</section>
{/* Category Navigation */}
<section className="py-4 bg-gradient-to-br from-orange-50/50 via-amber-50/30 to-red-50/50" data-testid="category-section">
<div className="max-w-full mx-auto px-2 sm:px-3 lg:px-4">
<div className="text-center mb-6">
<h2 className="text-2xl font-bold text-gray-900 mb-2">Shop by Category</h2>
<p className="text-gray-600">Find exactly what you're looking for</p>
</div>
{categoriesLoading ? (
<div className="flex flex-col items-center">
<LoadingSpinner text="Loading categories..." />
<div className="flex justify-center space-x-8 mt-4">
{[...Array(6)].map((_, i) => (
<div key={i} className="flex flex-col items-center">
<Skeleton className="w-16 h-16 rounded-full mb-2" />
<Skeleton className="w-16 h-4" />
</div>
))}
</div>
</div>
) : (
<CategoryNav
categories={categories}
selectedCategory={selectedCategory}
onCategorySelect={setSelectedCategory}
/>
)}
</div>
</section>
{/* Products Section */}
<section className="py-8 bg-white" data-testid="products-section">
<div className="max-w-full mx-auto px-2 sm:px-3 lg:px-4">
<div className="text-center mb-6">
<h2 className="text-2xl font-bold text-gray-900 mb-3" data-testid="products-title">
{showingResults ? 'Search Results' : 'Featured Products'}
</h2>
<p className="text-gray-600 max-w-2xl mx-auto text-sm" data-testid="products-subtitle">
{showingResults ?
`${displayProducts.length} products found` :
'Quality products from trusted sellers'
}
</p>
</div>
{isProductsLoading ? (
<div className="flex flex-col items-center">
<LoadingSpinner text={showingResults ? "Searching products..." : "Loading featured products..."} />
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-4 xl:grid-cols-5 gap-2 sm:gap-3 md:gap-4 mt-4 w-full">
{[...Array(12)].map((_, i) => (
<div key={i} className="glass-card rounded-2xl p-4">
<Skeleton className="aspect-square w-full mb-4 rounded-xl" />
<Skeleton className="h-4 w-3/4 mb-2" />
<Skeleton className="h-4 w-1/2 mb-2" />
<Skeleton className="h-6 w-1/4" />
</div>
))}
</div>
</div>
) : (
<ProductGrid products={displayProducts} />
)}
</div>
</section>
{/* All Stores Section */}
<section className="py-8 bg-gradient-to-br from-orange-50/30 via-amber-50/20 to-red-50/30" data-testid="stores-section">
<div className="max-w-full mx-auto px-2 sm:px-3 lg:px-4">
<div className="text-center mb-8">
<h2 className="text-4xl font-bold text-gray-900 mb-4" data-testid="stores-title">
🏪 Trusted Stores
</h2>
<p className="text-gray-600 max-w-3xl mx-auto text-lg" data-testid="stores-subtitle">
Explore our network of verified sellers and their unique collections. Each store is carefully vetted to ensure quality and reliability.
</p>
<div className="flex items-center justify-center mt-4 space-x-6">
<div className="flex items-center">
<ShieldCheck className="h-5 w-5 text-green-500 mr-2" />
<span className="text-sm text-gray-600">Verified Sellers</span>
</div>
<div className="flex items-center">
<CreditCard className="h-5 w-5 text-blue-500 mr-2" />
<span className="text-sm text-gray-600">Secure Payments</span>
</div>
<div className="flex items-center">
<Star className="h-5 w-5 text-yellow-500 mr-2" />
<span className="text-sm text-gray-600">Quality Guaranteed</span>
</div>
</div>
</div>
{storesLoading ? (
<div className="flex flex-col items-center">
<LoadingSpinner text="Loading stores..." />
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 xl:grid-cols-5 gap-4 mt-4 w-full">
{[...Array(6)].map((_, i) => (
<div key={i} className="glass-card rounded-2xl p-6">
<Skeleton className="h-32 w-full mb-4 rounded-xl" />
<div className="flex items-center space-x-4">
<Skeleton className="w-16 h-16 rounded-full" />
<div className="flex-1">
<Skeleton className="h-6 w-3/4 mb-2" />
<Skeleton className="h-4 w-full" />
</div>
</div>
</div>
))}
</div>
</div>
) : stores.length > 0 ? (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 xl:grid-cols-5 gap-4">
{stores.map((store: Store) => (
<StoreCard key={store.id} store={store} />
))}
</div>
) : (
<div className="text-center py-12">
<p className="text-muted-foreground" data-testid="no-stores">
No stores available at the moment.
</p>
</div>
)}
</div>
</section>
{/* Why Choose Shoposphere Section - Moved to Bottom */}
<section className="py-8 bg-gradient-to-br from-orange-100/40 via-amber-100/30 to-red-100/40" data-testid="features-section">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="text-center mb-8">
<h2 className="text-2xl font-bold text-gray-900 mb-3">Why Choose Shoposphere?</h2>
<p className="text-gray-600 max-w-2xl mx-auto">Experience the best of online shopping with our premium features</p>
</div>
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
<div className="text-center p-6 rounded-xl bg-white/70 hover:bg-white/90 transition-all duration-300">
<div className="w-16 h-16 mx-auto mb-4 bg-gradient-to-r from-orange-500 to-red-500 rounded-full flex items-center justify-center">
<Truck className="h-8 w-8 text-white" />
</div>
<h3 className="text-lg font-semibold text-gray-900 mb-3">Fast Delivery</h3>
<p className="text-gray-600 text-sm">Get your orders delivered quickly with our express shipping network</p>
</div>
<div className="text-center p-6 rounded-xl bg-white/70 hover:bg-white/90 transition-all duration-300">
<div className="w-16 h-16 mx-auto mb-4 bg-gradient-to-r from-orange-500 to-red-500 rounded-full flex items-center justify-center">
<ShieldCheck className="h-8 w-8 text-white" />
</div>
<h3 className="text-lg font-semibold text-gray-900 mb-3">Secure Shopping</h3>
<p className="text-gray-600 text-sm">Your payments and personal data are protected with advanced security</p>
</div>
<div className="text-center p-6 rounded-xl bg-white/70 hover:bg-white/90 transition-all duration-300">
<div className="w-16 h-16 mx-auto mb-4 bg-gradient-to-r from-orange-500 to-red-500 rounded-full flex items-center justify-center">
<HeadphonesIcon className="h-8 w-8 text-white" />
</div>
<h3 className="text-lg font-semibold text-gray-900 mb-3">24/7 Support</h3>
<p className="text-gray-600 text-sm">Our customer service team is always ready to help you</p>
</div>
</div>
</div>
</section>
</div>
);
}
|