diff --git a/src/views/Product/Desktop/ProductOverAll/index.js b/src/views/Product/Desktop/ProductOverAll/index.js
index c236668..922dce7 100644
--- a/src/views/Product/Desktop/ProductOverAll/index.js
+++ b/src/views/Product/Desktop/ProductOverAll/index.js
@@ -66,11 +66,11 @@ export const ProductOverAll = ({
-
+
- {activeProduct?.suggestedCounter ? (
+ {physicalProduct?.suggestedCounter ? (
- بیش از {activeProduct?.suggestedCounter} نفر امتیاز داده اند
+ بیش از {physicalProduct?.suggestedCounter} نفر امتیاز داده اند
) : null}
@@ -155,22 +155,22 @@ export const ProductOverAll = ({
- {activeProduct?.properties?.length && (
+ {physicalProduct?.properties?.length && (
,
+ components: ,
},
{
title: "نقد و بررسی",
diff --git a/src/views/Products/layouts/Desktop/Main.js b/src/views/Products/layouts/Desktop/Main.js
index 9faa438..ee0b62e 100644
--- a/src/views/Products/layouts/Desktop/Main.js
+++ b/src/views/Products/layouts/Desktop/Main.js
@@ -12,8 +12,6 @@ import { book, publicApi } from "../../../../redux/actions";
import moment from "jalali-moment";
import dropdownIcon from "../../../../assets/icons/dropdown-blue.svg";
-import Posts from "./Posts";
-import Pagination from "./Pagination";
const num = 6;
export const Main = ({
@@ -22,30 +20,24 @@ export const Main = ({
sortMethods,
filterOptions,
setFilterOptions,
- isMobile,
+ useless
}) => {
const [filterLoading, setFilterLoading] = useState(false);
const [page, setPage] = useState(1);
- console.log(page);
const [total, setTotal] = useState(books.length);
useEffect(() => {
- // setFilterLoading(() => true);
- // setTimeout(() => {
- // setFilterLoading(() => false);
- // }, 500);
setPage(1);
}, [filterOptions]);
useEffect(() => {
- window.scrollTo(0, 0);
- }, []);
-
- useEffect(() => {
- setTotal(books.length);
+ if(books?.length){
+ setTotal(books.length);
+ window.scroll({top : 0, behavior : 'smooth'});
+ }
}, [books]);
- const Items = (type) => {
+ const Items = React.useCallback((type) => {
const { grade, subject, available, sort, productType } = filterOptions;
let byGradeFilter;
let bySubjectFilter;
@@ -59,7 +51,9 @@ export const Main = ({
if (subject) {
bySubjectFilter = byGradeFilter?.filter(
(book) =>
- book?.product[type]?.name?.indexOf(subject) !== -1 ||
+ book?.product
+ ?.find((product) => product?.productType === type)
+ ?.name?.indexOf(subject) !== -1 ||
book?.name.indexOf(subject) !== -1
);
} else {
@@ -67,7 +61,8 @@ export const Main = ({
}
if (available) {
byAvailableFilter = bySubjectFilter?.filter(
- (book) => book.product[type].price
+ (book) =>
+ book.product?.find((product) => product?.productType === type)?.price
);
} else {
byAvailableFilter = bySubjectFilter;
@@ -75,11 +70,15 @@ export const Main = ({
if (sort) {
if (sort === "ارزان ترین") {
bySortFilter = byAvailableFilter?.sort(
- (a, b) => a.product[type].price - b.product[type].price
+ (a, b) =>
+ a.product?.find((product) => product?.productType === type)?.price -
+ b.product?.find((product) => product?.productType === type)?.price
);
} else if (sort === "محبوب ترین") {
bySortFilter = byAvailableFilter?.sort(
- (a, b) => a.product[type].rate - b.product[type].rate
+ (a, b) =>
+ a.product?.find((product) => product?.productType === type)?.rate -
+ b.product?.find((product) => product?.productType === type)?.rate
);
} else if (sort === "جدیدترین") {
bySortFilter = byAvailableFilter?.sort(
@@ -91,17 +90,24 @@ export const Main = ({
} else {
bySortFilter = byAvailableFilter;
}
- console.log("render here !");
return bySortFilter;
- // setTotal(bySortFilter.length);
- };
+ },[books, filterOptions, grades]);
+
+ const elements = React.useMemo(() => {
+ return Items(2);
+ },[books, filterOptions]);
+
+ const vods = React.useMemo(() => {
+ return Items(4);
+ },[books, filterOptions]);
- const elements = Items(1);
- const vods = Items(2);
- console.log(elements.length);
+ const lastPage = React.useMemo(() => {
+ return Math.floor((elements.length - 1) / num) + 1;
+ },[books, filterOptions]);
- const lastPage = Math.floor((elements.length - 1) / num) + 1;
- const pages = lastPage > 1 ? [...Array(lastPage)].map((e, i) => i + 1) : [];
+ const pages = React.useMemo(() => {
+ return lastPage > 1 ? [...Array(lastPage)].map((e, i) => i + 1) : [];
+ },[books, filterOptions]);
return (
-
)}
-
- {books.length > 0 && (
-
+ {books.length ? (
+
- )}
-
+ ) : null}
{elements
?.slice((page - 1) * num, page * num)
@@ -261,7 +264,6 @@ export const Main = ({
type={0}
/>
))}
-
{/* pagination */}
{pages.map((e) => (