-
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.
✏️WIP - Add an item from a planet to the ship cargo.
- Loading branch information
alexlee-dev
committed
Aug 21, 2019
1 parent
68a861d
commit 9dc9e5c
Showing
9 changed files
with
224 additions
and
20 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
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,17 @@ | ||
// * ACTION TYPES | ||
const STORE_CARGO = 'STORE_CARGO' | ||
const SET_SHIP = 'SET_SHIP' | ||
|
||
// * ACTION GENERATORS | ||
export const storeCargo = item => ({ | ||
type: STORE_CARGO, | ||
payload: { | ||
item | ||
} | ||
}) | ||
|
||
export const setShip = ship => ({ type: SET_SHIP, payload: { ship } }) | ||
|
||
// * PROMISES | ||
|
||
// * THUNKS |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,77 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { connect } from 'react-redux' | ||
import { Box, Text, Button } from 'grommet' | ||
import { Add } from 'grommet-icons' | ||
import useLocalStorage from '../hooks/useLocalStorage' | ||
import { storeCargo } from '../redux/actions/ship' | ||
import { removeItem } from '../redux/actions/world' | ||
|
||
const PlanetsView = ({ planets, handleStoreCargo }) => { | ||
const [storagePlanets, setStoragePlanets] = useLocalStorage('planets', []) | ||
|
||
const PlanetsView = ({ planets }) => { | ||
return ( | ||
<div> | ||
{planets.map(({ items, isHomePlanet, name }) => ( | ||
<div key={name}> | ||
<h2>{isHomePlanet ? name + ' - Home Planet' : name}</h2> | ||
<span>Items:</span> | ||
<pre>{JSON.stringify(items, null, 2)}</pre> | ||
{items.map(item => { | ||
const { id, name, space, value } = item | ||
|
||
return ( | ||
<Box | ||
align="center" | ||
direction="row" | ||
fill="horizontal" | ||
justify="start" | ||
key={id} | ||
> | ||
<Box pad="medium"> | ||
<Text>Name: {name}</Text> | ||
</Box> | ||
<Box pad="medium"> | ||
<Text>Space: {space}</Text> | ||
</Box> | ||
<Box pad="medium"> | ||
<Text>Value: {value}</Text> | ||
</Box> | ||
<Box pad="medium"> | ||
<Button | ||
hoverIndicator | ||
icon={<Add />} | ||
onClick={() => | ||
handleStoreCargo(item, storagePlanets, setStoragePlanets) | ||
} | ||
plain | ||
/> | ||
</Box> | ||
</Box> | ||
) | ||
})} | ||
</div> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
||
PlanetsView.propTypes = { | ||
dispatch: PropTypes.func.isRequired, | ||
planets: PropTypes.array.isRequired | ||
planets: PropTypes.array.isRequired, | ||
handleStoreCargo: PropTypes.func.isRequired | ||
} | ||
|
||
const mapStateToProps = ({ world }) => ({ planets: world.planets }) | ||
|
||
export default connect(mapStateToProps)(PlanetsView) | ||
const mapDispatchToProps = dispatch => ({ | ||
handleStoreCargo: (item, currentPlanets, setStoragePlanets) => { | ||
// * dispatch an action to store the item in ship cargo | ||
dispatch(storeCargo(item)) | ||
// * dispatch an action to remove the item from the list of stored items on this planet | ||
dispatch(removeItem(item)) | ||
} | ||
}) | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(PlanetsView) |
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