From 0fdbb61e6d949e66db01bc1d88354adff0b34e84 Mon Sep 17 00:00:00 2001 From: mahdi Date: Mon, 4 Jul 2022 18:24:37 +0430 Subject: [PATCH] =?UTF-8?q?=D8=A7=D8=B6=D8=A7=D9=81=D9=87=20=DA=A9=D8=B1?= =?UTF-8?q?=D8=AF=D9=86=20=D8=B5=D9=81=D8=AD=D9=87=20=D8=A8=D9=86=D8=AF?= =?UTF-8?q?=DB=8C=20|=2090?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Navbar/index.js | 2 + src/components/StarRating/index.js | 3 +- src/views/Products/layouts/Desktop/Main.js | 130 +++++++++------------ src/views/ShoppingCart/index.js | 1 + 4 files changed, 57 insertions(+), 79 deletions(-) diff --git a/src/components/Navbar/index.js b/src/components/Navbar/index.js index f15fe2e..b8af9bf 100644 --- a/src/components/Navbar/index.js +++ b/src/components/Navbar/index.js @@ -64,6 +64,8 @@ function Navbar({ useEffect(() => { if (!isMobile && isLogin) { console.log(111); + // console.log/("gl3"); + getCartProducts(); } }, [isLogin]); diff --git a/src/components/StarRating/index.js b/src/components/StarRating/index.js index 1b04634..b50ffee 100644 --- a/src/components/StarRating/index.js +++ b/src/components/StarRating/index.js @@ -19,7 +19,8 @@ function StarRating({ const [rate, setRating] = React.useState(null); useMemo(() => { - if (isLogin) getUserProducts(); + //console.log("gl2"); + // if (isLogin && !userProducts.length) getUserProducts(); }, []); React.useEffect(() => { diff --git a/src/views/Products/layouts/Desktop/Main.js b/src/views/Products/layouts/Desktop/Main.js index 3e38572..3ae9a3a 100644 --- a/src/views/Products/layouts/Desktop/Main.js +++ b/src/views/Products/layouts/Desktop/Main.js @@ -14,7 +14,7 @@ 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 = ({ books, grades, @@ -24,17 +24,23 @@ export const Main = ({ isMobile, }) => { const [filterLoading, setFilterLoading] = useState(false); + const [page, setPage] = useState(1); + const [total, setTotal] = useState(books.length); useEffect(() => { - setFilterLoading(() => true); - setTimeout(() => { - setFilterLoading(() => false); - }, 500); + // setFilterLoading(() => true); + // setTimeout(() => { + // setFilterLoading(() => false); + // }, 500); + setPage(1); }, [filterOptions]); useEffect(() => { window.scrollTo(0, 0); }, []); + useEffect(() => { + setTotal(books.length); + }, [books]); const Items = (type) => { const { grade, subject, available, sort, productType } = filterOptions; @@ -82,83 +88,22 @@ export const Main = ({ } else { bySortFilter = byAvailableFilter; } - return type === 2 - ? bySortFilter?.map((item, index) => ( - - )) - : bySortFilter?.map((product, index) => ( - <> - {(productType ? productType === "کتاب دیجیتال" : true) && ( - - - - )} - {(productType ? productType === "کتاب فیزیکی" : true) && ( - - - - )} - - )); + console.log("render here !"); + return bySortFilter; + // setTotal(bySortFilter.length); }; - // pagination - const [posts, setPosts] = useState([]); - const [loading, setLoading] = useState(false); - const [currentPage, setCurrentPage] = useState(1); - const [postsPerPage] = useState(10); - - useEffect(() => { - const fetchPosts = async () => { - setLoading(true); - const res = await axios.get("https://jsonplaceholder.typicode.com/posts"); - setPosts(res.data); - setLoading(false); - }; - - fetchPosts(); - }, []); - - // get current post - const indexOfLastPost = currentPage * postsPerPage; - const indexOfFirstPost = indexOfLastPost - postsPerPage; - const currentPosts = posts.slice(indexOfFirstPost, indexOfLastPost); - - // change page - const paginate = (pageNumber) => setCurrentPage(pageNumber); - + const elements = Items(1); + const vods = Items(2); + console.log(elements.length); + const lastPage = Math.floor((elements.length - 1) / num) + 1; + const pages = lastPage > 1 ? [...Array(lastPage)].map((e, i) => i + 1) : []; return (
-
+ {/*

My Blog

-
+
*/}
} > - {Items(2)} + {vods.map((item, index) => ( + + ))}
)}
- {Items(1)} + {elements + ?.slice((page - 1) * num, page * num) + .map((product, index) => ( + + ))} +
+ {pages.map((e) => ( +
setPage(e)} + > + {e} +
+ ))} +
diff --git a/src/views/ShoppingCart/index.js b/src/views/ShoppingCart/index.js index cbb6de5..eccbaae 100644 --- a/src/views/ShoppingCart/index.js +++ b/src/views/ShoppingCart/index.js @@ -41,6 +41,7 @@ function ShoppingCart({ const [phase, setPhase] = useState("products"); const navigation = useNavigate(); useEffect(() => { + console.log("gl1") if (isLogin) getList(); getFactorInfo({ userId: user?.id }); setHeaderOptions(headerOptions);