goodsList.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {OneGood, GoodsNotFound} from "./index";
  2. import {createStore, combineReducers, applyMiddleware, bindActionCreators} from 'redux';
  3. import {getData, actionGoods, urlUpload} from "../reducers/index";
  4. import {Provider, connect} from 'react-redux';
  5. import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from 'react-router-dom';
  6. const mapStateToProps = state => ({
  7. state: state,
  8. arr: getData(state),
  9. // search: getGoods(state)
  10. });
  11. const mapDispatchToProps = dispatch => bindActionCreators({
  12. getData: actionGoods
  13. }, dispatch);
  14. const GoodsList = ({arr = [], className = "goods", onAdd}) => {
  15. const history = useHistory();
  16. // console.log(arr)
  17. if(arr.length == 0) {
  18. return(
  19. <>
  20. <GoodsNotFound/>
  21. </>
  22. )
  23. }
  24. return (
  25. <div className = {className}>
  26. {arr.map((good) =>
  27. <div key = {`${Math.random}${good._id}`}className = "oneGood">
  28. <OneGood id = {good._id} name = {good.name} price = {good.price}
  29. image = {good.images ? `${urlUpload}/${good.images[0].url}` : `https://images.ua.prom.st/2259265311_korobka-syurpriz-dlya.jpg`}
  30. />
  31. <div>
  32. {(history.location.pathname.includes(`/catalog/`) || history.location.pathname.includes(`/search/`)) && <button onClick = {() => onAdd(good.name, good.price, good._id, good.description, good.images)}>В кошик</button>}
  33. {history.location.pathname.includes(`/orderPage/`) && <button onClick = {() => onAdd(good.name, good.price, good._id, good.description, good.images)}>Додати до замовлення</button>}
  34. </div>
  35. </div>
  36. )}
  37. </div>
  38. )
  39. }
  40. // const CGoodsList = connect(mapStateToProps, mapDispatchToProps)(GoodsList);
  41. export default GoodsList;