Browse Source

-copypaste

maryluis 4 years ago
parent
commit
64968f4526

+ 4 - 16
shop/src/components/goodsCategory.js

@@ -4,13 +4,13 @@ import thunk from 'redux-thunk';
 import {actionPromise} from "./index"
 import {gql, actionGoods, getGoods} from "../reducers/index";
 import { useEffect } from 'react';
-import {OneGood, CGoodsList} from "./index";
+import {OneGood, GoodsList} from "./index";
 
 
   
   const mapStateToProps = state => ({
     state: state,
-    goods: getGoods(state)
+    goods: getGoods(state, "goods")
   });
   
   const mapDispatchToProps = dispatch => bindActionCreators({
@@ -19,24 +19,12 @@ import {OneGood, CGoodsList} from "./index";
   
 
 
-
-// const GoodsList = ({goods = [], className = "goods"}) => {
-//   return (
-//     <div className = {className}>          
-//       {goods.map((good) => <OneGood key = {good._id} name = {good.name} price = {good.price} image = {good.images[0].url}/>)}
-//     </div>
-//   )
-// }
-
-//  const CGoodsList = connect(mapStateToProps, mapDispatchToProps)(GoodsList);
-
-
-const GoodsCategory = ({id, tittle = "Товари", getData}) => {
+const GoodsCategory = ({goods, id, tittle = "Товари", getData}) => {
   useEffect(() =>  getData(id), [id])
   return(
       <>
         <div className = "goodsWrapper">
-            <CGoodsList />
+            <GoodsList arr = {goods}/>
         </div>
       </>
   )

+ 5 - 5
shop/src/components/goodsList.js

@@ -17,8 +17,8 @@ import {Provider, connect} from 'react-redux';
 
 
 
-const GoodsList = ({goods = [], className = "goods"}) => {
-  if(goods.length == 0) {
+const GoodsList = ({arr = [], className = "goods"}) => {
+  if(arr.length == 0) {
     return(
         <>
         <GoodsNotFound/>
@@ -27,11 +27,11 @@ const GoodsList = ({goods = [], className = "goods"}) => {
 }
   return (
     <div className = {className}>          
-      {goods.map((good) => <OneGood key = {good._id} name = {good.name} price = {good.price} image = {good.images ? `http://shop-roles.asmer.fs.a-level.com.ua/${good.images[0].url}` : `https://images.ua.prom.st/2259265311_korobka-syurpriz-dlya.jpg`}/>)}
+      {arr.map((good) => <OneGood key = {good._id} name = {good.name} price = {good.price} image = {good.images ? `http://shop-roles.asmer.fs.a-level.com.ua/${good.images[0].url}` : `https://images.ua.prom.st/2259265311_korobka-syurpriz-dlya.jpg`}/>)}
     </div>
   )
 }
 
- const CGoodsList = connect(mapStateToProps, mapDispatchToProps)(GoodsList);
+//  const CGoodsList = connect(mapStateToProps, mapDispatchToProps)(GoodsList);
 
- export default CGoodsList;
+ export default GoodsList;

+ 1 - 2
shop/src/components/goodsListSearch.js

@@ -6,14 +6,13 @@ import {GoodsNotFound } from "./index";
 
 const mapStateToProps = state => ({
     state: state,
-    search: getSearchedGoods(state)
+    search: getGoods(state, "search")
   });
   
   const mapDispatchToProps = dispatch => bindActionCreators({
     getData: actionSearch
   }, dispatch);
   
-let image = ""
 
 
 const GoodsListSearch = ({search = [], className = "goods"}) => {

+ 6 - 10
shop/src/components/goodsSearch.js

@@ -4,34 +4,30 @@ import thunk from 'redux-thunk';
 import {actionPromise} from "./index"
 import {gql, actionGoods, getGoods, actionSearch} from "../reducers/index";
 import { useEffect } from 'react';
-import {OneGood, CGoodsList} from "./index";
+import {OneGood, GoodsList} from "./index";
 import CGoodsListSearch from './goodsListSearch';
 
 const mapStateToProps = state => ({
     state: state,
-    search: getGoods(state)
+    search: getGoods(state, "search")
   });
   
   const mapDispatchToProps = dispatch => bindActionCreators({
     getData: actionSearch
   }, dispatch);
 
-  const GoodsSearch = ({name, getData}) => {
-      console.log(name)
+  const GoodsSearch = ({search, name, getData}) => {
+    console.log(search)
     useEffect(() =>  getData(name), [name])
     return(
     <>
             <div className = "goodsWrapper">
-                <CGoodsListSearch />
+              <GoodsList arr = {search}/>
             </div>
     </>
     )
   }
    const CGoodsSearch = connect(mapStateToProps, mapDispatchToProps)(GoodsSearch);
 
-// const CGoodsSearch = ({}) => {
-//     return(
-//         <h2>Hello</h2>
-//     )
-// }
+
   export default CGoodsSearch;

+ 2 - 2
shop/src/components/index.js

@@ -9,7 +9,7 @@ import actionCatalogCard from "../reducers/reducerCat";
 import Links from "./links"
 import CGoodsCategory from "./goodsCategory";
 import OneGood from './oneGood';
-import CGoodsList from "./goodsList";
+import GoodsList from "./goodsList";
 import SearchInput from "./searchInput";
 import CGoodsSearch from "./goodsSearch";
 import CGoodsListSearch from "./goodsListSearch";
@@ -17,7 +17,7 @@ import GoodsNotFound from "./goodsNotFound";
 
 
 
-export {Header,Footer, actionCatalogCard, Main, Links, CGoodsCategory, OneGood, CGoodsList, SearchInput, CGoodsSearch, CGoodsListSearch, GoodsNotFound};
+export {Header,Footer, actionCatalogCard, Main, Links, CGoodsCategory, OneGood, GoodsList, SearchInput, CGoodsSearch, CGoodsListSearch, GoodsNotFound};
 
 
 

+ 3 - 3
shop/src/reducers/getGoods.js

@@ -1,10 +1,10 @@
 
 
 
-  const getGoods = state => {
+  const getGoods = (state, key) => {
   
-    if(state.promiseRed.goods && state.promiseRed.goods.payload) {
-        return state.promiseRed.goods.payload.data.GoodFind
+    if(state.promiseRed[key] && state.promiseRed[key].payload) {
+        return state.promiseRed[key].payload.data.GoodFind
     }
   
     return [];

+ 0 - 12
shop/src/reducers/getSearchedGoods.js

@@ -1,12 +0,0 @@
-
-
-  const getSearchedGoods = state => {
-  
-    if(state.promiseRed.search && state.promiseRed.search.payload) {
-        return state.promiseRed.search.payload.data.GoodFind
-    }
-  
-    return [];
-  };
-
-  export default getSearchedGoods;

+ 2 - 2
shop/src/reducers/index.js

@@ -5,7 +5,7 @@ import gql from "./gql";
 import actionGoods from "./actionGoods"
 import getGoods from "./getGoods";
 import {actionSearch} from "./actionsearch";
-import getSearchedGoods from "./getSearchedGoods";
+
 
 
 function promiseReducer(state={}, action){
@@ -25,7 +25,7 @@ function promiseReducer(state={}, action){
     promiseRed: promiseReducer
   }), compose(applyMiddleware(thunk)))
 
-export {actionPromise, gql, actionGoods, getGoods, promiseReducer, store, actionSearch, getSearchedGoods};
+export {actionPromise, gql, actionGoods, getGoods, promiseReducer, store, actionSearch};