From fab86aa933109bbc989e2073b9a17064ca3b0ecc Mon Sep 17 00:00:00 2001 From: Reza_ashrafi Date: Tue, 12 Jul 2022 16:00:33 +0430 Subject: [PATCH] update 13 files --- src/router.js | 16 +++++- src/views/Blog/index.js | 4 -- src/views/Blogs/index.js | 9 +--- .../Dashboard/layouts/Main/MyBooks/index.js | 51 ++++++++++--------- .../Main/UserItems/ProductSuggestion/index.js | 8 +-- src/views/Home/Desktop/index.js | 9 +--- src/views/Home/Portrait/Private/index.js | 20 ++------ src/views/Home/index.js | 4 -- src/views/Product/index.js | 2 - src/views/Products/index.js | 5 -- src/views/Products/layouts/Desktop/Main.js | 1 - src/views/ShoppingCart/index.js | 6 +-- src/views/Videos/index.js | 20 -------- 13 files changed, 52 insertions(+), 103 deletions(-) diff --git a/src/router.js b/src/router.js index dc20aa3..22bf210 100644 --- a/src/router.js +++ b/src/router.js @@ -2,7 +2,14 @@ import React, { useEffect } from "react"; import { BrowserRouter, Routes, Route } from "react-router-dom"; import { Navigate } from "react-router-dom"; import { connect } from "react-redux"; -import { publicApi, menu, config, userProduct } from "./redux/actions"; +import { + publicApi, + menu, + config, + userProduct, + book, + blog, +} from "./redux/actions"; import Navbar from "./components/Navbar"; import BG from "./components/BG"; import BottomNavigation from "./components/BottomNavigation"; @@ -47,10 +54,15 @@ function Router({ device, getAvailableForSell, getUserProducts, + getBookList, + getBlogList, }) { useEffect(() => { getAvailableForSell(); getUserProducts(); + getBookList({ vod: true }); + getBlogList(); + window.scroll({ top: 0, behavior: "smooth" }); const width = window.innerWidth; if (width <= 640) { setDevice("mobile"); @@ -627,6 +639,8 @@ const mapDispatchToProps = { setDevice: config.setDevice, getAvailableForSell: config.getAvailableForSell, getUserProducts: userProduct.list, + getBookList: book.list, + getBlogList: blog.list, }; export default connect(mapStateToProps, mapDispatchToProps)(Router); diff --git a/src/views/Blog/index.js b/src/views/Blog/index.js index 6596025..11b1bc9 100644 --- a/src/views/Blog/index.js +++ b/src/views/Blog/index.js @@ -18,18 +18,15 @@ export const Blog = ({ blog, setHeaderOptions, headerOptions, - getList, blogs, }) => { let { id } = useParams(); useEffect(() => { - getList(); setHeaderOptions(headerOptions); }, []); useEffect(() => { - window.scroll({ top: 0, behavior: "smooth" }); getInfo({ id }); }, [id]); @@ -181,7 +178,6 @@ const mapStateToProps = (state) => ({ const mapDispatchToProps = { getInfo: blog.info, - getList: blog.list, setHeaderOptions: publicApi.setHeaderOptions, }; diff --git a/src/views/Blogs/index.js b/src/views/Blogs/index.js index ea58929..ed9a724 100644 --- a/src/views/Blogs/index.js +++ b/src/views/Blogs/index.js @@ -1,6 +1,6 @@ import React, { useEffect } from "react"; import { connect } from "react-redux"; -import { blog, publicApi } from "../../redux/actions"; +import { publicApi } from "../../redux/actions"; import { Carousel } from "@trendyol-js/react-carousel"; import Hashtags from "./layouts/Hashtags"; @@ -17,7 +17,6 @@ import arrow from "../../assets/icons/dropdown-blue.svg"; export const Blogs = ({ isMobile, - getList, blogs, setHeaderOptions, headerOptions, @@ -25,11 +24,6 @@ export const Blogs = ({ }) => { useEffect(() => { setHeaderOptions(headerOptions); - getList(); - }, []); - - useEffect(() => { - window.scroll({ top: 0, behavior: "smooth" }); }, []); return ( @@ -143,7 +137,6 @@ const mapStateToProps = (state) => ({ }); const mapDispatchToProps = { - getList: blog.list, setHeaderOptions: publicApi.setHeaderOptions, }; diff --git a/src/views/Dashboard/layouts/Main/MyBooks/index.js b/src/views/Dashboard/layouts/Main/MyBooks/index.js index 7594afa..fa03405 100644 --- a/src/views/Dashboard/layouts/Main/MyBooks/index.js +++ b/src/views/Dashboard/layouts/Main/MyBooks/index.js @@ -2,19 +2,17 @@ import React, { useEffect } from "react"; import { connect } from "react-redux"; import { Link } from "react-router-dom"; -import Product from "../../../../../components/Product"; import ProductSuggestion from "../UserItems/ProductSuggestion"; import { ScrollingCarousel } from "@trendyol-js/react-carousel"; -import { Book } from "../../../../Home/Portrait/Private/MyBooks"; import Progress from "../../../../../components/Progress"; -export const MyBooks = ({ books, grades, isMobile }) => { +export const MyBooks = ({ books, grades, isMobile, userProducts }) => { const Book = ({ book }) => { return ( -
  • - +
  • + { {book.name}

    {`پایه ${ - grades[book.gradeId] + grades[book?.product?.book?.gradeId] }`}

    @@ -38,36 +36,39 @@ export const MyBooks = ({ books, grades, isMobile }) => { ); }; - useEffect(() => { - window.scrollTo(0, 0); - }, []); - return (
    -
    - {/* {books.slice(0, 1).map((product, index) => ( - - ))} */} -
    -

    +

    +
    +

    {window.t("کتاب های من")}

    - - {books?.map((book, index) => ( - - ))} - + {userProducts?.filter((product) => product?.condition >= 2) + ?.length ? ( + + {userProducts + ?.filter((product) => product?.condition >= 2) + ?.map((book, index) => ( + + ))} + + ) : null}
    - + {/* */}
    ); }; const mapStateToProps = (state) => ({ - books: state.book.list, + userProducts: state.userProduct.list, grades: state.publicApi.grades, - isMobile: state.publicApi.isMobile, + isMobile: state.config.device === 'mobile', + books: state.book.list, }); const mapDispatchToProps = {}; diff --git a/src/views/Dashboard/layouts/Main/UserItems/ProductSuggestion/index.js b/src/views/Dashboard/layouts/Main/UserItems/ProductSuggestion/index.js index e15dc2e..9c00c62 100644 --- a/src/views/Dashboard/layouts/Main/UserItems/ProductSuggestion/index.js +++ b/src/views/Dashboard/layouts/Main/UserItems/ProductSuggestion/index.js @@ -10,8 +10,8 @@ function Suggestion({ products, grades, isMobile }) { پیشنهادات ما به شما - {products.length > 0 && ( -
    + {products?.length ? ( +
    } > - {products.map((product, index) => ( + {products?.map((product, index) => ( ))}
    - )} + ) : null}
    ); } diff --git a/src/views/Home/Desktop/index.js b/src/views/Home/Desktop/index.js index 46ca531..90556a1 100644 --- a/src/views/Home/Desktop/index.js +++ b/src/views/Home/Desktop/index.js @@ -2,13 +2,13 @@ import React, { useEffect } from "react"; import { connect } from "react-redux"; import SalesContainer from "./SalesContainer"; -import { book, publicApi } from "../../../redux/actions"; +import { publicApi } from "../../../redux/actions"; import Part2 from "./Part2"; import HomeImg from "../../../assets/images/HomeImg.png"; import Part4 from "./Part4"; import Design2D from "../../../components/Design2D"; -const DesktopHome = ({ grades, getBooks, books }) => { +const DesktopHome = ({ grades, books }) => { const banners = [ { flex: 4, @@ -51,10 +51,6 @@ const DesktopHome = ({ grades, getBooks, books }) => { }, ]; - useEffect(() => { - getBooks({vod : true}); - },[]); - return (
    @@ -80,7 +76,6 @@ const mapStateToProps = (state) => ({ }); const mapDispatchToProps = { - getBooks: book.list, setHeaderOptions: publicApi.setHeaderOptions, }; diff --git a/src/views/Home/Portrait/Private/index.js b/src/views/Home/Portrait/Private/index.js index 9088fe3..d8a55cb 100644 --- a/src/views/Home/Portrait/Private/index.js +++ b/src/views/Home/Portrait/Private/index.js @@ -1,20 +1,11 @@ import React, { useEffect } from "react"; import { connect } from "react-redux"; -import { book, blog } from "../../../../redux/actions"; import MyBooks from "./MyBooks"; import Shop from "./Shop"; import Videos from "./Videos"; import Blogs from "./Blogs"; -function Private({ getList, products, blogs, getBlogList, grades }) { - useEffect(() => { - if (products.length === 0) { - getList({ vod: true }); - } - if(blogs.length === 0){ - getBlogList(); - } - }, []); +function Private({ products, blogs, grades }) { return (
    @@ -28,12 +19,7 @@ function Private({ getList, products, blogs, getBlogList, grades }) { const mapStateToProps = (state) => ({ products: state.book.list, blogs: state.blog.list, - grades: state.publicApi.grades + grades: state.publicApi.grades, }); -const mapDispatchToProps = { - getList: book.list, - getBlogList: blog.list -}; - -export default connect(mapStateToProps, mapDispatchToProps)(Private); +export default connect(mapStateToProps)(Private); diff --git a/src/views/Home/index.js b/src/views/Home/index.js index 4a9f034..7741bbd 100644 --- a/src/views/Home/index.js +++ b/src/views/Home/index.js @@ -10,10 +10,6 @@ function Home({ setHeaderOptions, headerOptions, isMobile }) { setHeaderOptions(headerOptions); }, []); - useEffect(() => { - window.scrollTo(0, 0); - }, []); - return ( <> {isMobile ? ( diff --git a/src/views/Product/index.js b/src/views/Product/index.js index 5b4e1b4..033bb13 100644 --- a/src/views/Product/index.js +++ b/src/views/Product/index.js @@ -3,7 +3,6 @@ import { connect } from "react-redux"; import { toast } from "react-toastify"; import { book, userProduct, publicApi, dialog } from "../../redux/actions"; import { Link, useNavigate } from "react-router-dom"; -import proxy from "../../redux/proxy"; import location from "../../utils/location"; import separate from "../../utils/separate"; @@ -110,7 +109,6 @@ export const Product = ({ useEffect(() => { if (book && isMobile) { setHeaderOptions({ ...headerOptions, productId: book?.id }); - window.scroll({ top: 0, behavior: "smooth" }); } }, [book]); return ( diff --git a/src/views/Products/index.js b/src/views/Products/index.js index 1aefab3..be9e7d4 100644 --- a/src/views/Products/index.js +++ b/src/views/Products/index.js @@ -1,5 +1,4 @@ import React, { useState, useEffect, useCallback } from "react"; -import { Link } from "react-router-dom"; import { connect } from "react-redux"; import Sidebar from "./layouts/Desktop/Sidebar"; @@ -14,16 +13,13 @@ export const Products = ({ isDark, isMobile, books, - getList, grades, setHeaderOptions, headerOptions, desktopContentTransform, }) => { useEffect(() => { - getList({ vod: true }); setHeaderOptions(headerOptions); - window.scroll({top: 0, behavior : 'smooth'}); }, []); return ( @@ -64,7 +60,6 @@ const mapStateToProps = (state) => ({ }); const mapDispatchToProps = { - getList: book.list, gradeFilter: book.gradeFilter, setHeaderOptions: publicApi.setHeaderOptions, setFilterOptions: book.setFilterOptions, diff --git a/src/views/Products/layouts/Desktop/Main.js b/src/views/Products/layouts/Desktop/Main.js index d4e91db..1c71a71 100644 --- a/src/views/Products/layouts/Desktop/Main.js +++ b/src/views/Products/layouts/Desktop/Main.js @@ -33,7 +33,6 @@ export const Main = ({ useEffect(() => { if(books?.length){ setTotal(books.length); - window.scroll({top : 0, behavior : 'smooth'}); } }, [books]); diff --git a/src/views/ShoppingCart/index.js b/src/views/ShoppingCart/index.js index 2119903..bc9b29b 100644 --- a/src/views/ShoppingCart/index.js +++ b/src/views/ShoppingCart/index.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useMemo, useCallback } from "react"; +import React, { useState, useEffect, useMemo } from "react"; import { userProduct, userFactor, @@ -26,7 +26,6 @@ function ShoppingCart({ isMobile, factorInfo, user, - getList, getFactorInfo, headerOptions, setHeaderOptions, @@ -41,8 +40,6 @@ function ShoppingCart({ const [phase, setPhase] = useState("products"); const navigation = useNavigate(); useEffect(() => { - console.log("gl1"); - if (isLogin) getList(); getFactorInfo({ userId: user?.id }); setHeaderOptions(headerOptions); }, []); @@ -407,7 +404,6 @@ const mapStateToProps = (state) => ({ }); const mapDispatchToProps = { - getList: userProduct.list, getInfo: userProduct.info, getFactorInfo: userFactor.info, payFactor: userFactor.payment, diff --git a/src/views/Videos/index.js b/src/views/Videos/index.js index 6d97acd..1cdfdbd 100644 --- a/src/views/Videos/index.js +++ b/src/views/Videos/index.js @@ -11,30 +11,10 @@ function Videos({ headerOptions, setHeaderOptions, getList, videos, grades }) { useEffect(() => { setHeaderOptions(headerOptions); - getList({ vod: true }); - }, []); - - useEffect(() => { - // alert(); - window.scrollTo(0, 0); }, []); return (
    - {/*
    - -
    -
    - -
    -
    - -
    */}