From 217deb72095f2cbcf3790f9af51c688e03f7ac8b Mon Sep 17 00:00:00 2001 From: alexlee-dev Date: Thu, 22 Aug 2019 13:06:51 -0700 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20ItemTimer=20uses=20real=20time.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ItemTimer.js | 5 +++-- src/util.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/ItemTimer.js b/src/components/ItemTimer.js index bfe2250..5c5e1c9 100644 --- a/src/components/ItemTimer.js +++ b/src/components/ItemTimer.js @@ -1,17 +1,18 @@ import React, { useState, useEffect } from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' -import moment from 'moment' import { setTimerRunning, clearItems, refreshItems } from '../redux/actions/world' +import { createDuration } from '../util' const ItemTimer = ({ handleTimerStarted, handleTimerStopped, world }) => { const { isTimerRunning } = world - let duration = moment.duration({ minutes: 10, seconds: 0 }) + let duration = createDuration() + const [timeLeft, setTimeLeft] = useState( `${duration.minutes()} minutes ${duration.seconds()} seconds` ) diff --git a/src/util.js b/src/util.js index 03d4776..7a156b9 100644 --- a/src/util.js +++ b/src/util.js @@ -1,5 +1,6 @@ import { itemList, planets } from './constants' import uuidv4 from 'uuid/v4' +import moment from 'moment' const getPlanetName = () => { const planet = planets[Math.floor(Math.random() * planets.length)] @@ -71,3 +72,16 @@ export const saveState = state => { console.error(error) } } + +export const createDuration = () => { + const deadline = moment().minutes(60) + const now = moment() + + const minutesLeft = deadline + .clone() + .subtract(now.minutes(), 'minutes') + .minutes() + const secondsLeft = 60 - now.seconds() + + return moment.duration({ minutes: minutesLeft, seconds: secondsLeft }) +} \ No newline at end of file From de59ad720445d19076722c1de3c60fbea183c34a Mon Sep 17 00:00:00 2001 From: alexlee-dev Date: Thu, 22 Aug 2019 18:41:29 -0700 Subject: [PATCH 2/4] =?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 + +