|
@@ -0,0 +1,80 @@
|
|
|
+import {Provider, connect} from 'react-redux';
|
|
|
+import {createStore, combineReducers, applyMiddleware, bindActionCreators} from 'redux';
|
|
|
+import thunk from 'redux-thunk';
|
|
|
+import {actionPromise} from "./index"
|
|
|
+import gql from "./gql";
|
|
|
+import { useEffect } from 'react';
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+const actionGoods = (_id) => {
|
|
|
+ return async dispatch => {
|
|
|
+ const queryJson = JSON.stringify([{
|
|
|
+ "categories._id": `${_id}`
|
|
|
+ }]);
|
|
|
+
|
|
|
+ await dispatch(actionPromise(`goods`, gql (
|
|
|
+ `query goods($query: String) {
|
|
|
+ GoodFind(query: $query ) {
|
|
|
+ name, price,
|
|
|
+ images{url}, _id
|
|
|
+ categories {
|
|
|
+ _id
|
|
|
+ createdAt
|
|
|
+ name
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }` ,{ query: queryJson })))
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// const OneGood = ({className = "oneGood", image, name, price}) => {
|
|
|
+// return (
|
|
|
+// <>
|
|
|
+// <div>
|
|
|
+// <h5>{name}</h5>
|
|
|
+// <span>{price}грн</span>
|
|
|
+// <img src = {`http://shop-roles.asmer.fs.a-level.com.ua/${image}`}/>
|
|
|
+// </div>
|
|
|
+// </>
|
|
|
+// )
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+// const Goods = ({className = "goods", state, goods = [], getData, id}) => {
|
|
|
+// useEffect(() => goods.length == 0 && getData(id), [])
|
|
|
+// console.log(goods)
|
|
|
+// return(
|
|
|
+// <>
|
|
|
+// <h1>{id}</h1>
|
|
|
+// <div className = {className}>
|
|
|
+
|
|
|
+// {/* <button onClick = {() => getData(id)}>hello</button> */}
|
|
|
+// {goods.map(good => <OneGood name = {good.name} price = {good.price} image = {good.images[0].url}/>)}
|
|
|
+// </div>
|
|
|
+// </>
|
|
|
+// )
|
|
|
+// }
|
|
|
+
|
|
|
+// const getGoods = state => {
|
|
|
+// console.log(state);
|
|
|
+
|
|
|
+// if(state.promiseRed.data && state.promiseRed.data.payload) {
|
|
|
+// return state.promiseRed.data.payload.data.GoodFind
|
|
|
+// }
|
|
|
+
|
|
|
+// return [];
|
|
|
+// };
|
|
|
+
|
|
|
+// const mapStateToProps = state => ({
|
|
|
+// state: state,
|
|
|
+// goods: getGoods(state)
|
|
|
+// });
|
|
|
+
|
|
|
+// const mapDispatchToProps = dispatch => bindActionCreators({
|
|
|
+// getData: actionGoods
|
|
|
+// }, dispatch);
|
|
|
+
|
|
|
+ export default actionGoods;
|