import React from 'react'; import { AnnouncementBar } from '../layout/AnnouncementBar'; import { Header } from '../layout/Header'; import { Navbar } from '../layout/Navbar'; import { Footer } from '../layout/Footer'; import { FloatingButtons } from '../components/FloatingButtons'; import { StickyHeaderSpacer } from '../components/StickyHeaderSpacer'; import { HomeHeroRow } from '../sections/HomeHeroRow'; import { PromoCardsSection } from '../sections/PromoCardsSection'; import { CategoriesSection } from '../sections/CategoriesSection'; import { NewArrivalsSection } from '../sections/NewArrivalsSection'; import { PromoBannersSection } from '../sections/PromoBannersSection'; import { HotDealsSection } from '../sections/HotDealsSection'; import { RecentlyLaunchedSection } from '../sections/RecentlyLaunchedSection'; import { BrandsSection } from '../sections/BrandsSection'; import { UltimateTechSection } from '../sections/UltimateTechSection'; import { ArticlesSection } from '../sections/ArticlesSection'; import { FeaturesSection } from '../sections/FeaturesSection'; import { catalogServerService } from '../services/api/catalogServerService'; import { mapCatalogProductToProduct } from '../utils/productMapper'; import { Product } from '../types'; import { buildHomepageSections, isSectionVisible, normalizeLayoutPayload, } from '../lib/layoutConfig'; import { sortHomeSectionsByOrder } from '../lib/techshopHome'; /** * Always fetch fresh layout so admin Visible/Hidden + display_order apply. * Homepage stack matches TechShop demo: * https://demo.templatemonster.com/demo/501755.html */ export const dynamic = 'force-dynamic'; export const revalidate = 0; export default async function Home() { let layoutData: any[] = []; let dbProducts: any[] = []; let categoriesData: any[] = []; let brandsData: any[] = []; let productsError = false; const [productsResult, layoutResult, categoriesResult, brandsResult] = await Promise.allSettled([ catalogServerService.getProducts(), catalogServerService.fetchLayoutConfigOnServer(), catalogServerService.getCategories(), catalogServerService.getBrands(), ]); if (productsResult.status === 'fulfilled') { dbProducts = productsResult.value || []; } else { console.error('Homepage products fetch failed:', productsResult.reason); productsError = true; } if (layoutResult.status === 'fulfilled') { layoutData = normalizeLayoutPayload(layoutResult.value); } else { console.error('Homepage layout fetch failed:', layoutResult.reason); } if (categoriesResult.status === 'fulfilled') { categoriesData = categoriesResult.value || []; } if (brandsResult.status === 'fulfilled') { brandsData = brandsResult.value || []; } const catalogProducts: Product[] = dbProducts.length > 0 ? dbProducts.map(mapCatalogProductToProduct) : []; const { activeSections, sectionsData, layoutLoaded } = buildHomepageSections(layoutData); /** Honor dashboard Visible/Hidden (`metadata_json.is_active`) for every section. */ const show = (key: string) => isSectionVisible(activeSections, key, layoutLoaded); const orderedKeys = sortHomeSectionsByOrder(sectionsData).map((s) => s.key); const productsLoading = false; const sectionNodes: Record = { hero_slider: show('hero_slider') ? ( ) : null, promo_cards: show('promo_cards') ? ( ) : null, featured_categories: show('featured_categories') ? ( ) : null, editorial_story: show('editorial_story') ? ( ) : null, promo_banners: show('promo_banners') ? ( ) : null, deal_of_the_day: show('deal_of_the_day') ? ( ) : null, recently_launched: show('recently_launched') ? ( ) : null, official_brands: show('official_brands') ? ( ) : null, ultimate_tech: show('ultimate_tech') ? ( ) : null, tech_blog: show('tech_blog') ? ( ) : null, trust_badges: show('trust_badges') ? ( ) : null, }; return (
{/* After Header + Navbar so sticky chrome reserves full height */}
{orderedKeys.map((key) => sectionNodes[key] ?? null)}
); }