maryluis před 4 roky
rodič
revize
f0b5215f29

+ 1 - 1
shop/src/App.css

@@ -207,7 +207,7 @@ content {
   background-color: rgb(10, 10, 10);
   border: 2px solid;
   border-color:rgb(229, 229, 243);
-  border-radius: 20%;
+  border-radius: 5%;
 }
 .goodCard h2 {
   text-align: center;

+ 2 - 32
shop/src/components/goodCard.js

@@ -1,5 +1,5 @@
 import { connect } from "react-redux";
-import {gql, urlUpload, actionPromise} from "../reducers";
+import {gql, urlUpload, actionPromise, actionGoodCard, getGoods} from "../reducers";
 import {createStore, combineReducers, applyMiddleware, bindActionCreators} from 'redux';
 import { useEffect, useState } from 'react';
 import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from 'react-router-dom';
@@ -8,28 +8,9 @@ import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from
 
 
 
-const actionGoodCard = (_id) => {
-    const queryJson = JSON.stringify([{
-        "_id": `${_id}`
-      }]);
-    return (actionPromise(`goodCard`, gql (
-        `query oneGood($query: String) {
-            GoodFindOne(query: $query) {
-                _id
-                createdAt
-                name
-                description
-                price
-                images{url}
-            }
-          }
-    ` ,{ query: queryJson})))
-  }
-
-
   const mapStateToProps = state => ({
     state: state,
-    goodCard: getGood(state, "goodCard")
+    goodCard: getGoods(state, "goodCard", "GoodFindOne")
   });
   
   const mapDispatchToProps = dispatch => bindActionCreators({
@@ -38,14 +19,6 @@ const actionGoodCard = (_id) => {
   
 
 
-  const getGood = (state, key) => {
-  
-    if(state.promiseRed[key] && state.promiseRed[key].payload) {
-        return state.promiseRed[key].payload.data.GoodFindOne
-    }
-  
-    return null;
-  };
 
 
 
@@ -71,9 +44,6 @@ const actionGoodCard = (_id) => {
 
       width > 900 ? setFinallyWidth(true) : setFinallyWidth(false);
 
-      // startWidth !== finallyWidth &&  history.push("./catalog")
-
-
       }
 
 

+ 1 - 1
shop/src/components/goodsCategory.js

@@ -10,7 +10,7 @@ import {OneGood, GoodsList} from "./index";
   
   const mapStateToProps = state => ({
     state: state,
-    goods: getGoods(state, "goods")
+    goods: getGoods(state, "goods", "GoodFind")
   });
   
   const mapDispatchToProps = dispatch => bindActionCreators({

+ 1 - 1
shop/src/components/goodsSearch.js

@@ -9,7 +9,7 @@ import {OneGood, GoodsList} from "./index";
 
 const mapStateToProps = state => ({
     state: state,
-    search: getGoods(state, "search")
+    search: getGoods(state, "search", "GoodFind")
   });
   
   const mapDispatchToProps = dispatch => bindActionCreators({

+ 22 - 0
shop/src/reducers/actionGoodCard.js

@@ -0,0 +1,22 @@
+import {actionPromise, gql} from "./index";
+
+
+const actionGoodCard = (_id) => {
+    const queryJson = JSON.stringify([{
+        "_id": `${_id}`
+      }]);
+    return (actionPromise(`goodCard`, gql (
+        `query oneGood($query: String) {
+            GoodFindOne(query: $query) {
+                _id
+                createdAt
+                name
+                description
+                price
+                images{url}
+            }
+          }
+    ` ,{ query: queryJson})))
+  }
+
+  export default actionGoodCard;

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

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

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

@@ -7,7 +7,8 @@ import getGoods from "./getGoods";
 import {actionSearch} from "./actionsearch";
 import actionLogin from "./actionLogin";
 import authReducer from "./authReducer";
-import {actionAuthLogin, actionAuthLogout} from "./actionAuthLog"
+import {actionAuthLogin, actionAuthLogout} from "./actionAuthLog";
+import actionGoodCard from "./actionGoodCard";
 
 
 
@@ -30,7 +31,7 @@ function promiseReducer(state={}, action){
   }), compose(applyMiddleware(thunk)))
 
 export {actionPromise, gql, actionGoods, getGoods, promiseReducer, store, actionSearch,
-   actionLogin, authReducer, actionAuthLogin, actionAuthLogout, urlUpload};
+   actionLogin, authReducer, actionAuthLogin, actionAuthLogout, urlUpload, actionGoodCard};