'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 ( <>
{t('category.search.not_found')}
{t('category.search.link')}