добавил переход к продуктам по категории при нажатии на карточку
This commit is contained in:
1 parent
d4f9aebf00
commit
524d9e3deb
2 files changed
+14
-7
No files matched your search
@@ -1,18 +1,25 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import styles from "./Catalog.module.css";
|
import styles from "./Catalog.module.css";
|
||||||
import { useAppSelector } from "../../app/hooks";
|
import { useAppDispatch, useAppSelector } from "../../app/hooks";
|
||||||
|
import { setSelectedCategory } from "./categoriesSlice";
|
||||||
|
import { fetchProductsByCategory, setFilters, setPage } from "./productsSlice";
|
||||||
|
|
||||||
interface Props {
|
|
||||||
onSelect?: (id:number) => void
|
|
||||||
}
|
|
||||||
|
|
||||||
const CategoryCards: React.FC<Props> = ({ onSelect }) => {
|
const CategoryCards: React.FC = () => {
|
||||||
const categories = useAppSelector(s => s.categories.items);
|
const categories = useAppSelector(s => s.categories.items);
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
const onSelect = (catId:number) => {
|
||||||
|
dispatch(setSelectedCategory(catId));
|
||||||
|
dispatch(setFilters({}));
|
||||||
|
dispatch(setPage(1));
|
||||||
|
dispatch(fetchProductsByCategory({ categoryId: catId, page: 1, limit: 9 }));
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.grid}>
|
<div className={styles.grid}>
|
||||||
{categories.map(c => (
|
{categories.map(c => (
|
||||||
<div key={c.id} className={styles.card} onClick={() => onSelect?.(c.id)}>
|
<div key={c.id} className={styles.card} onClick={() => onSelect(c.id)}>
|
||||||
{c.image ? <img src={c.image} alt={c.name} className={styles.img} /> : <img src="/mnt/data/c9552f5e-1741-4845-8d5f-9d438f068636.png" alt={c.name} className={styles.img} />}
|
{c.image ? <img src={c.image} alt={c.name} className={styles.img} /> : <img src="/mnt/data/c9552f5e-1741-4845-8d5f-9d438f068636.png" alt={c.name} className={styles.img} />}
|
||||||
<div className={styles.name}>{c.name}</div>
|
<div className={styles.name}>{c.name}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const ProductsPage: React.FC = () => {
|
|||||||
<SidebarCategories />
|
<SidebarCategories />
|
||||||
<div className={styles.content}>
|
<div className={styles.content}>
|
||||||
{!selectedCategoryId ? (
|
{!selectedCategoryId ? (
|
||||||
<CategoryCards onSelect={(id) => {}} />
|
<CategoryCards/>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<div className={styles.leftControls}>
|
<div className={styles.leftControls}>
|
||||||
|
|||||||
Reference in new issue
Block a user