Skip to content

Commit

Permalink
Merge ca17be8 into f25e56a
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Lee committed Aug 21, 2019
2 parents f25e56a + ca17be8 commit 23ad123
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const App = ({

const homePlanet = planets.find(planet => planet.isHomePlanet === true)

console.log({ homePlanet, shipLocation })
const value = homePlanet.location
const name = homePlanet.name

Expand Down
27 changes: 23 additions & 4 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,27 @@ const getPlanetName = () => {
return planet
}

export const generateItems = () => {
export const generateItems = possibleDestinations => {
const items = []

console.log({ possibleDestinations })

for (let i = 0; i < 5; i++) {
const destinationPlanet =
possibleDestinations[
Math.floor(Math.random() * possibleDestinations.length)
]

const item = Object.assign(
{},
itemList[Math.floor(Math.random() * itemList.length)],
{ id: uuidv4() }
{
id: uuidv4(),
destination: {
name: destinationPlanet.name,
value: destinationPlanet.location
}
}
)
items.push(item)
}
Expand All @@ -25,13 +38,19 @@ export const generatePlanets = () => {

for (let i = 0; i < 3; i++) {
const isHomePlanet = i === 0
const items = generateItems()
const location = Math.floor(Math.random() * 100 + 1)
const name = getPlanetName()

planets.push({ isHomePlanet, items, location, name })
planets.push({ isHomePlanet, location, name })
}

planets.forEach((planet, i) => {
const otherPlanets = [...planets]
otherPlanets.splice(i, 1)

planet.items = generateItems(otherPlanets)
})

return planets
}

Expand Down
5 changes: 4 additions & 1 deletion src/views/planets.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const PlanetsView = ({
</Box>
<span>Items:</span>
{items.map(item => {
const { id, name, space, value } = item
const { destination, id, name, space, value } = item

return (
<Box
Expand All @@ -58,6 +58,9 @@ const PlanetsView = ({
<Box pad="medium">
<Text>Value: {value}</Text>
</Box>
<Box pad="medium">
<Text>Destination: {destination.name}</Text>
</Box>
{shipLocationValue === location && (
<Box pad="medium">
<Button
Expand Down
12 changes: 9 additions & 3 deletions src/views/ship.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const ShipView = ({ cargo, handleRemoveCargo, location }) => {
{cargo.map(item => (
<Box direction="row" gap="medium" key={item.id}>
<Text>{item.name}</Text>
<Text weight="bold">Destination:</Text>
<Text>{item.destination.name}</Text>
<Button
hoverIndicator
icon={<Subtract />}
Expand All @@ -22,10 +24,14 @@ const ShipView = ({ cargo, handleRemoveCargo, location }) => {
</Box>
))}
<h3>Location:</h3>
<Box gap="small" margin={{ left: 'medium'}}>
<Text size="small" weight="bold">Value:</Text>
<Box gap="small" margin={{ left: 'medium' }}>
<Text size="small" weight="bold">
Value:
</Text>
<Text size="small">{location.value}</Text>
<Text size="small" weight="bold">Name:</Text>
<Text size="small" weight="bold">
Name:
</Text>
<Text size="small">{location.name}</Text>
</Box>
</div>
Expand Down

0 comments on commit 23ad123

Please sign in to comment.