'use client'; import { useEffect, useMemo } from 'react'; import clsx from 'clsx'; import { useSearchParams } from 'next/navigation'; import { CategoryHeader } from './category-header'; import { Filters } from './filters'; import { Pagination } from '@theme/components'; import { ProductItem } from '@theme/views/product-item'; import { GetCategoryResponse } from '@akinon/next/types'; import { useAppDispatch, useAppSelector } from '@akinon/next/redux/hooks'; import { setFacets, setMenuOpen } from '@theme/redux/reducers/category'; import CategoryActiveFilters from '@theme/views/category/category-active-filters'; import { useLocalization } from '@akinon/next/hooks'; import { Link, LoaderSpinner } from '@akinon/next/components'; import { ROUTES } from '@theme/routes'; import { useRouter } from '@akinon/next/hooks'; import { RootState } from '@theme/redux/store'; interface ListPageProps { data: GetCategoryResponse; } export default function ListPage(props: ListPageProps) { const { data } = props; const dispatch = useAppDispatch(); const isMenuOpen = useAppSelector( (state: RootState) => state.category.isMenuOpen ); const searchParams = useSearchParams(); const router = useRouter(); const layoutSize = useMemo( () => Number(searchParams.get('layout') ?? 3), [searchParams] ); const page = useMemo( () => Number(searchParams.get('page') ?? 1), [searchParams] ); const itemDimensions = useMemo(() => { switch (layoutSize) { case 2: return { width: 510, height: 765 }; case 3: default: return { width: 340, height: 510 }; } }, [layoutSize]); useEffect(() => { if (page > 1 && data.products?.length === 0) { const newUrl = new URL(window.location.href); newUrl.searchParams.delete('page'); router.push(newUrl.pathname + newUrl.search, undefined); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [searchParams, data.products, page]); const { t } = useLocalization(); useEffect(() => { dispatch(setFacets(data.facets)); // eslint-disable-next-line react-hooks/exhaustive-deps }, [data.facets]); return ( <>
dispatch(setMenuOpen(open))} />
dispatch(setMenuOpen(false))} className={clsx( 'transition-opacity duration-300 ease-linear lg:hidden', isMenuOpen ? 'fixed bg-black bg-opacity-60 inset-0 z-10 opacity-100' : 'opacity-0' )} >
dispatch(setMenuOpen(true))} sortOptions={data.sorters} />
{data.products?.length === 0 && page === 1 && (

{t('category.search.not_found')}

{t('category.search.link')}
)} {data.products?.length === 0 && page > 1 && }
{data?.products?.map((product, index) => ( ))}
{data?.products?.length > 0 && ( )}
); }