From de59ad720445d19076722c1de3c60fbea183c34a Mon Sep 17 00:00:00 2001 From: alexlee-dev Date: Thu, 22 Aug 2019 18:41:29 -0700 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8Ability=20to=20sell=20/=20buy=20it?= =?UTF-8?q?ems=20by=20quantity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ItemDisplay.js | 49 +++++++++++ src/components/ItemDisplayInput.js | 67 +++++++++++++++ src/components/PlanetDisplay.js | 89 ++++++++++++++++++++ src/redux/actions/ship.js | 5 +- src/redux/actions/world.js | 5 +- src/redux/reducers/ship.js | 47 ++++++++++- src/redux/reducers/world.js | 38 +++++++-- src/util.js | 3 +- src/views/planets.js | 131 ++--------------------------- src/views/ship.js | 20 +++-- 10 files changed, 311 insertions(+), 143 deletions(-) create mode 100644 src/components/ItemDisplay.js create mode 100644 src/components/ItemDisplayInput.js create mode 100644 src/components/PlanetDisplay.js diff --git a/src/components/ItemDisplay.js b/src/components/ItemDisplay.js new file mode 100644 index 0000000..29e4047 --- /dev/null +++ b/src/components/ItemDisplay.js @@ -0,0 +1,49 @@ +import React from 'react' +import PropTypes from 'prop-types' +import { Box, Text } from 'grommet' +import { connect } from 'react-redux' + +import ItemDisplayInput from './ItemDisplayInput' + +const ItemDisplay = ({ item, location, shipLocationValue }) => { + const { destination, id, name, quantity, space, value } = item + + return ( + + + Name: {name} + + + Quantity: {quantity} + + + Space: {space} + + + Value: {value} + + + Destination: {destination.name} + + {shipLocationValue === location && } + + ) +} + +ItemDisplay.propTypes = { + item: PropTypes.object.isRequired, + location: PropTypes.number.isRequired, + shipLocationValue: PropTypes.number.isRequired +} + +const mapStateToProps = ({ ship }) => ({ + shipLocationValue: ship.location.value +}) + +export default connect(mapStateToProps)(ItemDisplay) diff --git a/src/components/ItemDisplayInput.js b/src/components/ItemDisplayInput.js new file mode 100644 index 0000000..71941a4 --- /dev/null +++ b/src/components/ItemDisplayInput.js @@ -0,0 +1,67 @@ +import React, { useState } from 'react' +import PropTypes from 'prop-types' +import { Box, Button } from 'grommet' +import { Add } from 'grommet-icons' +import { connect } from 'react-redux' +import { storeCargo } from '../redux/actions/ship' +import { removeItem } from '../redux/actions/world' + +const ItemDisplayInput = ({ + handleStoreCargo, + item, + shipCargoVolumeRemaining +}) => { + const { id, quantity } = item + + const [value, setValue] = useState(0) + + return ( + + +
+ +
+
Should render the component. 1`] = ` Name: Test Item
+
+ + Quantity: + +
@@ -121,8 +158,9 @@ exports[` Should render the component. 1`] = ` class="StyledBox-sc-13pk1d4-0 hroMnY" > +
+ +
+
Should render the component. 1`] = ` Name: Test Item
+
+ + Quantity: + +
@@ -183,8 +248,9 @@ exports[` Should render the component. 1`] = ` class="StyledBox-sc-13pk1d4-0 hroMnY" > +
+ +
+
Should render the component. 1`] = ` Name: Test Item
+
+ + Quantity: + +
@@ -245,8 +338,9 @@ exports[` Should render the component. 1`] = ` class="StyledBox-sc-13pk1d4-0 hroMnY" > +
+ +
+
Should render the component. 1`] = ` Name: Test Item
+
+ + Quantity: + +
@@ -307,8 +428,9 @@ exports[` Should render the component. 1`] = ` class="StyledBox-sc-13pk1d4-0 hroMnY" > +
+ +
+
@@ -373,6 +513,15 @@ exports[` Should render the component. 1`] = ` Name: Test Item
+
+ + Quantity: + +
@@ -413,6 +562,15 @@ exports[` Should render the component. 1`] = ` Name: Test Item
+
+ + Quantity: + +
@@ -453,6 +611,15 @@ exports[` Should render the component. 1`] = ` Name: Test Item
+
+ + Quantity: + +
@@ -493,6 +660,15 @@ exports[` Should render the component. 1`] = ` Name: Test Item
+
+ + Quantity: + +
@@ -533,6 +709,15 @@ exports[` Should render the component. 1`] = ` Name: Test Item
+
+ + Quantity: + +
@@ -608,6 +793,15 @@ exports[` Should render the component. 1`] = ` Name: Test Item
+
+ + Quantity: + +
@@ -648,6 +842,15 @@ exports[` Should render the component. 1`] = ` Name: Test Item
+
+ + Quantity: + +
@@ -688,6 +891,15 @@ exports[` Should render the component. 1`] = ` Name: Test Item
+
+ + Quantity: + +
@@ -728,6 +940,15 @@ exports[` Should render the component. 1`] = ` Name: Test Item
+
+ + Quantity: + +
@@ -768,6 +989,15 @@ exports[` Should render the component. 1`] = ` Name: Test Item
+
+ + Quantity: + +
diff --git a/src/__tests__/views/__snapshots__/ship.js.snap b/src/__tests__/views/__snapshots__/ship.js.snap index c64b0ec..af80e3f 100644 --- a/src/__tests__/views/__snapshots__/ship.js.snap +++ b/src/__tests__/views/__snapshots__/ship.js.snap @@ -9,6 +9,20 @@ exports[` Should render the component. 1`] = `

Cargo

+
+ + Volume Remaining: + + + 4 + +
@@ -36,6 +50,22 @@ exports[` Should render the component. 1`] = `
+ + Quantity: + +
+ + 1 + +