|
|
@ -12,6 +12,7 @@ import { book, publicApi } from "../../../../redux/actions"; |
|
|
|
import moment from "jalali-moment"; |
|
|
|
import moment from "jalali-moment"; |
|
|
|
|
|
|
|
|
|
|
|
import dropdownIcon from "../../../../assets/icons/dropdown-blue.svg"; |
|
|
|
import dropdownIcon from "../../../../assets/icons/dropdown-blue.svg"; |
|
|
|
|
|
|
|
import filter from "../../../../assets/icons/filter-icon.svg"; |
|
|
|
const num = 6; |
|
|
|
const num = 6; |
|
|
|
|
|
|
|
|
|
|
|
export const Main = ({ |
|
|
|
export const Main = ({ |
|
|
@ -20,7 +21,7 @@ export const Main = ({ |
|
|
|
sortMethods, |
|
|
|
sortMethods, |
|
|
|
filterOptions, |
|
|
|
filterOptions, |
|
|
|
setFilterOptions, |
|
|
|
setFilterOptions, |
|
|
|
useless |
|
|
|
useless, |
|
|
|
}) => { |
|
|
|
}) => { |
|
|
|
const [filterLoading, setFilterLoading] = useState(false); |
|
|
|
const [filterLoading, setFilterLoading] = useState(false); |
|
|
|
const [page, setPage] = useState(1); |
|
|
|
const [page, setPage] = useState(1); |
|
|
@ -31,19 +32,23 @@ export const Main = ({ |
|
|
|
}, [filterOptions]); |
|
|
|
}, [filterOptions]); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if(books?.length){ |
|
|
|
if (books?.length) { |
|
|
|
setTotal(books.length); |
|
|
|
setTotal(books.length); |
|
|
|
|
|
|
|
window.scroll({ top: 0, behavior: "smooth" }); |
|
|
|
} |
|
|
|
} |
|
|
|
}, [books]); |
|
|
|
}, [books]); |
|
|
|
|
|
|
|
|
|
|
|
const Items = React.useCallback((type) => { |
|
|
|
const Items = React.useCallback( |
|
|
|
|
|
|
|
(type) => { |
|
|
|
const { grade, subject, available, sort, productType } = filterOptions; |
|
|
|
const { grade, subject, available, sort, productType } = filterOptions; |
|
|
|
let byGradeFilter; |
|
|
|
let byGradeFilter; |
|
|
|
let bySubjectFilter; |
|
|
|
let bySubjectFilter; |
|
|
|
let byAvailableFilter; |
|
|
|
let byAvailableFilter; |
|
|
|
let bySortFilter; |
|
|
|
let bySortFilter; |
|
|
|
if (grade) { |
|
|
|
if (grade) { |
|
|
|
byGradeFilter = books?.filter((book) => grades[book?.gradeId] === grade); |
|
|
|
byGradeFilter = books?.filter( |
|
|
|
|
|
|
|
(book) => grades[book?.gradeId] === grade |
|
|
|
|
|
|
|
); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
byGradeFilter = books; |
|
|
|
byGradeFilter = books; |
|
|
|
} |
|
|
|
} |
|
|
@ -61,7 +66,8 @@ export const Main = ({ |
|
|
|
if (available) { |
|
|
|
if (available) { |
|
|
|
byAvailableFilter = bySubjectFilter?.filter( |
|
|
|
byAvailableFilter = bySubjectFilter?.filter( |
|
|
|
(book) => |
|
|
|
(book) => |
|
|
|
book.product?.find((product) => product?.productType === type)?.price |
|
|
|
book.product?.find((product) => product?.productType === type) |
|
|
|
|
|
|
|
?.price |
|
|
|
); |
|
|
|
); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
byAvailableFilter = bySubjectFilter; |
|
|
|
byAvailableFilter = bySubjectFilter; |
|
|
@ -70,13 +76,15 @@ export const Main = ({ |
|
|
|
if (sort === window.t("ارزان ترین")) { |
|
|
|
if (sort === window.t("ارزان ترین")) { |
|
|
|
bySortFilter = byAvailableFilter?.sort( |
|
|
|
bySortFilter = byAvailableFilter?.sort( |
|
|
|
(a, b) => |
|
|
|
(a, b) => |
|
|
|
a.product?.find((product) => product?.productType === type)?.price - |
|
|
|
a.product?.find((product) => product?.productType === type) |
|
|
|
|
|
|
|
?.price - |
|
|
|
b.product?.find((product) => product?.productType === type)?.price |
|
|
|
b.product?.find((product) => product?.productType === type)?.price |
|
|
|
); |
|
|
|
); |
|
|
|
} else if (sort === window.t("محبوب ترین")) { |
|
|
|
} else if (sort === window.t("محبوب ترین")) { |
|
|
|
bySortFilter = byAvailableFilter?.sort( |
|
|
|
bySortFilter = byAvailableFilter?.sort( |
|
|
|
(a, b) => |
|
|
|
(a, b) => |
|
|
|
a.product?.find((product) => product?.productType === type)?.rate - |
|
|
|
a.product?.find((product) => product?.productType === type) |
|
|
|
|
|
|
|
?.rate - |
|
|
|
b.product?.find((product) => product?.productType === type)?.rate |
|
|
|
b.product?.find((product) => product?.productType === type)?.rate |
|
|
|
); |
|
|
|
); |
|
|
|
} else if (sort === window.t("جدیدترین")) { |
|
|
|
} else if (sort === window.t("جدیدترین")) { |
|
|
@ -90,23 +98,25 @@ export const Main = ({ |
|
|
|
bySortFilter = byAvailableFilter; |
|
|
|
bySortFilter = byAvailableFilter; |
|
|
|
} |
|
|
|
} |
|
|
|
return bySortFilter; |
|
|
|
return bySortFilter; |
|
|
|
},[books, filterOptions, grades]); |
|
|
|
}, |
|
|
|
|
|
|
|
[books, filterOptions, grades] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const elements = React.useMemo(() => { |
|
|
|
const elements = React.useMemo(() => { |
|
|
|
return Items(2); |
|
|
|
return Items(2); |
|
|
|
},[books, filterOptions]); |
|
|
|
}, [books, filterOptions]); |
|
|
|
|
|
|
|
|
|
|
|
const vods = React.useMemo(() => { |
|
|
|
const vods = React.useMemo(() => { |
|
|
|
return Items(4); |
|
|
|
return Items(4); |
|
|
|
},[books, filterOptions]);
|
|
|
|
}, [books, filterOptions]); |
|
|
|
|
|
|
|
|
|
|
|
const lastPage = React.useMemo(() => { |
|
|
|
const lastPage = React.useMemo(() => { |
|
|
|
return Math.floor((elements.length - 1) / num) + 1; |
|
|
|
return Math.floor((elements.length - 1) / num) + 1; |
|
|
|
},[books, filterOptions]); |
|
|
|
}, [books, filterOptions]); |
|
|
|
|
|
|
|
|
|
|
|
const pages = React.useMemo(() => { |
|
|
|
const pages = React.useMemo(() => { |
|
|
|
return lastPage > 1 ? [...Array(lastPage)].map((e, i) => i + 1) : []; |
|
|
|
return lastPage > 1 ? [...Array(lastPage)].map((e, i) => i + 1) : []; |
|
|
|
},[books, filterOptions]);
|
|
|
|
}, [books, filterOptions]); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div |
|
|
|
<div |
|
|
@ -115,63 +125,7 @@ export const Main = ({ |
|
|
|
> |
|
|
|
> |
|
|
|
<div className="flex w-full bg-blue rounded-lg border border-solid border-gray-200 p-2 items-center my-1.5 justify-center text-blue52"> |
|
|
|
<div className="flex w-full bg-blue rounded-lg border border-solid border-gray-200 p-2 items-center my-1.5 justify-center text-blue52"> |
|
|
|
<div className="flex text-sm items-center mr-2 ml-4"> |
|
|
|
<div className="flex text-sm items-center mr-2 ml-4"> |
|
|
|
<svg |
|
|
|
<img src={filter} className="w-5" alt="filter" /> |
|
|
|
xmlns="http://www.w3.org/2000/svg" |
|
|
|
|
|
|
|
width="24" |
|
|
|
|
|
|
|
height="24" |
|
|
|
|
|
|
|
viewBox="0 0 24 24" |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<g |
|
|
|
|
|
|
|
id="vuesax_linear_filter-tick" |
|
|
|
|
|
|
|
data-name="vuesax/linear/filter-tick" |
|
|
|
|
|
|
|
transform="translate(-620 -700)" |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<g id="filter-tick"> |
|
|
|
|
|
|
|
<path |
|
|
|
|
|
|
|
id="Vector" |
|
|
|
|
|
|
|
d="M9.5,4.75A4.678,4.678,0,0,1,8.82,7.2,4.735,4.735,0,0,1,4.75,9.5a4.62,4.62,0,0,1-2.56-.77A4.481,4.481,0,0,1,.69,7.2,4.686,4.686,0,0,1,0,4.75,4.754,4.754,0,0,1,4.75,0,4.421,4.421,0,0,1,5.79.12,4.74,4.74,0,0,1,9.5,4.75Z" |
|
|
|
|
|
|
|
transform="translate(632.13 710)" |
|
|
|
|
|
|
|
fill="none" |
|
|
|
|
|
|
|
stroke="rgba(6, 186, 206" |
|
|
|
|
|
|
|
strokeLinecap="round" |
|
|
|
|
|
|
|
strokeLinejoin="round" |
|
|
|
|
|
|
|
strokeWidth="1.5" |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
<path |
|
|
|
|
|
|
|
id="Vector-2" |
|
|
|
|
|
|
|
data-name="Vector" |
|
|
|
|
|
|
|
d="M0,1.17,1.17,2.34,3.7,0" |
|
|
|
|
|
|
|
transform="translate(635.03 713.58)" |
|
|
|
|
|
|
|
fill="none" |
|
|
|
|
|
|
|
stroke="rgba(6, 186, 206" |
|
|
|
|
|
|
|
strokeLinecap="round" |
|
|
|
|
|
|
|
strokeLinejoin="round" |
|
|
|
|
|
|
|
strokeWidth="1.5" |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
<path |
|
|
|
|
|
|
|
id="Vector-3" |
|
|
|
|
|
|
|
data-name="Vector" |
|
|
|
|
|
|
|
d="M0,0H24V24H0Z" |
|
|
|
|
|
|
|
transform="translate(644 724) rotate(180)" |
|
|
|
|
|
|
|
fill="none" |
|
|
|
|
|
|
|
opacity="0" |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
<g id="Group"> |
|
|
|
|
|
|
|
<path |
|
|
|
|
|
|
|
id="Vector-4" |
|
|
|
|
|
|
|
data-name="Vector" |
|
|
|
|
|
|
|
d="M17.38,2.02V4.24a3.825,3.825,0,0,1-1.01,2.33L14.61,8.12A4.421,4.421,0,0,0,13.57,8a4.754,4.754,0,0,0-4.75,4.75,4.686,4.686,0,0,0,.69,2.45,4.481,4.481,0,0,0,1.5,1.53v.34a2.23,2.23,0,0,1-.91,1.72l-1.41.91a2.058,2.058,0,0,1-3.13-1.72V12.63a3.91,3.91,0,0,0-.81-2.12L.91,6.47A3.407,3.407,0,0,1,0,4.45V2.12A2.051,2.051,0,0,1,2.02,0H15.36A2.027,2.027,0,0,1,17.38,2.02Z" |
|
|
|
|
|
|
|
transform="translate(623.31 702)" |
|
|
|
|
|
|
|
fill="none" |
|
|
|
|
|
|
|
stroke="rgba(6, 186, 206" |
|
|
|
|
|
|
|
strokeLinecap="round" |
|
|
|
|
|
|
|
strokeLinejoin="round" |
|
|
|
|
|
|
|
strokeWidth="1.5" |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
</g> |
|
|
|
|
|
|
|
</g> |
|
|
|
|
|
|
|
</g> |
|
|
|
|
|
|
|
</svg> |
|
|
|
|
|
|
|
<span className="text-tiny text-greenBA font-bold"> |
|
|
|
<span className="text-tiny text-greenBA font-bold"> |
|
|
|
{window.t("مرتب سازی") + "" + ":"} |
|
|
|
{window.t("مرتب سازی") + "" + ":"} |
|
|
|
</span> |
|
|
|
</span> |
|
|
|