-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alexlee-dev
committed
Aug 27, 2019
1 parent
46c6285
commit e29f8f1
Showing
8 changed files
with
194 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React, { useState } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { Box } from 'grommet' | ||
import { itemList } from '../constants' | ||
import { connect } from 'react-redux' | ||
import { createContract } from '../redux/actions/world' | ||
import { generateContract } from '../util' | ||
|
||
/** | ||
* Inputs for creating a contract. | ||
*/ | ||
const CreateContract = ({ handleCreateContract, planets }) => { | ||
const [itemType, setItemType] = useState(itemList[0]) | ||
const [destination, setDestination] = useState({ | ||
location: planets[0].location, | ||
name: planets[0].name | ||
}) | ||
|
||
return ( | ||
<Box width="medium"> | ||
<label htmlFor="item-type">Item Type</label> | ||
<select | ||
id="item-type" | ||
onChange={e => setItemType(JSON.parse(e.target.value))} | ||
> | ||
{itemList.map(item => ( | ||
<option key={item.name} value={JSON.stringify(item)}> | ||
{item.name} | ||
</option> | ||
))} | ||
</select> | ||
<label htmlFor="item-volume">Item Volume</label> | ||
<input | ||
disabled | ||
id="item-volume" | ||
type="number" | ||
value={itemType ? itemType.volume : 0} | ||
/> | ||
<label htmlFor="item-value">Item Value</label> | ||
<input | ||
disabled | ||
id="item-value" | ||
type="number" | ||
value={itemType ? itemType.value : 0} | ||
/> | ||
<label htmlFor="item-destination">Destination</label> | ||
<select | ||
id="item-destination" | ||
onChange={e => { | ||
const planet = planets.find(planet => planet.id === e.target.value) | ||
setDestination({ location: planet.location, name: planet.name }) | ||
}} | ||
> | ||
{planets.map(planet => ( | ||
<option key={planet.id} value={planet.id}> | ||
{planet.name} | ||
</option> | ||
))} | ||
</select> | ||
<button | ||
onClick={() => { | ||
handleCreateContract( | ||
generateContract(planets, itemType.name, destination) | ||
) | ||
}} | ||
> | ||
Create Contract | ||
</button> | ||
</Box> | ||
) | ||
} | ||
|
||
CreateContract.propTypes = { | ||
handleCreateContract: PropTypes.func.isRequired, | ||
planets: PropTypes.array.isRequired | ||
} | ||
|
||
const mapStateToProps = ({ world }) => ({ planets: world.planets }) | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
handleCreateContract: contract => dispatch(createContract(contract)) | ||
}) | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(CreateContract) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters