From 8b4b7b505e682816906aca0fe4c1fa580129bc26 Mon Sep 17 00:00:00 2001 From: Ernest Litvinenko Date: Mon, 18 Mar 2024 03:17:10 +0300 Subject: [PATCH] Fix catalog filters in mobile version. Add accordion animations --- src/pages/catalog/index.tsx | 121 ++++++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 48 deletions(-) diff --git a/src/pages/catalog/index.tsx b/src/pages/catalog/index.tsx index 8dedc08..5c734af 100644 --- a/src/pages/catalog/index.tsx +++ b/src/pages/catalog/index.tsx @@ -1,7 +1,7 @@ import { CheckboxGroup, Checkbox, - Button, Skeleton + Button, Skeleton, Accordion, AccordionItem } from "@nextui-org/react"; import Link from "next/link"; @@ -19,79 +19,99 @@ import {Img} from "react-image"; +const CheckboxUI = (obj: {id: number, name: string, values: {id: number, value: string}[]}) => { + return ( + + + + {obj.values && obj.values.map(val => ( + {val.value} + ))} + + + + + ) +} const FilterGenerator = ({filterPropertiesData}: Pick, "filterPropertiesData">) => { return ( -
-

Фильтры

- - {filterPropertiesData.map( obj => ( - - {obj.values && obj.values.map(val => ( - {val.value} + + + {filterPropertiesData.map(obj => ( + ))} - - - ))} -
+ + ) } -type CardProps = InferGetStaticPropsType['catalog'][0] & {isFavourite?: boolean} +type CardProps = InferGetStaticPropsType['catalog'][0] & { isFavourite?: boolean } const CatalogCard = (product: CardProps) => { const isClient = useClient() - const cartItems = useQuery({queryKey: ['cart'], queryFn: async () => { - const service = new LocalAPI() - return await service.getCartItems() - }}) + const cartItems = useQuery({ + queryKey: ['cart'], queryFn: async () => { + const service = new LocalAPI() + return await service.getCartItems() + } + }) const qs = useQueryClient() const toggleCart = useMutation({ - mutationFn: async ({productId, quantity}: { productId: number, quantity: number }) => { - const service = new LocalAPI() - if (cartItems.data!.find(({id}) => id === productId)) { - return await service.deleteCartItem(productId) - } - return await service.addCartItem(productId, quantity) - }, + mutationFn: async ({productId, quantity}: { productId: number, quantity: number }) => { + const service = new LocalAPI() + if (cartItems.data!.find(({id}) => id === productId)) { + return await service.deleteCartItem(productId) + } + return await service.addCartItem(productId, quantity) + }, onSuccess: () => { - qs.invalidateQueries({queryKey: ["cart"]}) + qs.invalidateQueries({queryKey: ["cart"]}) } }) return ( -
+
{ - isClient && product.properties.main_image && {product.name}}/> + isClient && product.properties.main_image && + {product.name}}/> }
- Стандарт API: {product.properties.api_standart} Тип: {product.properties.oil_type} + Стандарт API: {product.properties.api_standart} Тип: {product.properties.oil_type}

{product.name}

{ isClient ? - toggleFavourite(product.id)} className={`transition-colors absolute z-20 top-0 right-0 ${product.isFavourite ? "fill-primary" : "fill-[#E0E3E3]"}`}/> : null + toggleFavourite(product.id)} + className={`transition-colors absolute z-20 top-0 right-0 ${product.isFavourite ? "fill-primary" : "fill-[#E0E3E3]"}`}/> : null } -
+
{`${product.price.BASE}`.replace(/\B(?=(\d{3})+(?!\d))/g, ' ')} ₽ { isClient ? - : null + : null } - +
@@ -104,20 +124,21 @@ const Catalog = (props: InferGetStaticPropsType) => { const {favourites} = useSnapshot(favouritesStore) return ( -
- +
+ -
+
- { - props.catalog.map(product => - <> - - - ) - } -
-
+ { + props.catalog.map(product => + <> + + + ) + } +
+
) } @@ -126,7 +147,11 @@ export default Catalog; export const getStaticProps = async () => { const service = new LocalAPI() - const filterData = await service.getFilters() as {id: number, name: string, values: {id: number, value: string}[]}[] + const filterData = await service.getFilters() as { + id: number, + name: string, + values: { id: number, value: string }[] + }[] const catalogData = await service.getCatalogItems() as { id: number code: string,