Skip to content

Commit

Permalink
✏️ Convert setShipLocationName() + setShipLocationValue() to setShipL…
Browse files Browse the repository at this point in the history
…ocation().
  • Loading branch information
alexlee-dev committed Aug 24, 2019
1 parent 7028474 commit ecf00c8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 31 deletions.
12 changes: 5 additions & 7 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import React, { useEffect } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { generatePlanets } from './util'
import { setShipLocationValue, setShipLocationName } from './redux/actions/ship'
import { setShipLocation } from './redux/actions/ship'
import { setPlanets } from './redux/actions/world'
import View from './views/View'
import { Box } from 'grommet'
import CashDisplay from './components/CashDisplay'
import ItemTimer from './components/ItemTimer'
import Title from './components/Title'
import ViewSelector from './components/ViewSelector'
import TravelTimer from './components/TravelTimer';
import ContractsDisplay from './components/ContractsDisplay';
import TravelTimer from './components/TravelTimer'
import ContractsDisplay from './components/ContractsDisplay'

const App = ({ handleInitializeApplication, planets }) => {
useEffect(() => {
Expand Down Expand Up @@ -45,12 +45,10 @@ const mapDispatchToProps = dispatch => ({
handleInitializeApplication: () => {
const planets = generatePlanets()
const homePlanet = planets.find(planet => planet.isHomePlanet === true)
const value = homePlanet.location
const name = homePlanet.name
const location = { name: homePlanet.name, value: homePlanet.location }

dispatch(setPlanets(planets))
dispatch(setShipLocationValue(value))
dispatch(setShipLocationName(name))
dispatch(setShipLocation(location))
}
})

Expand Down
8 changes: 4 additions & 4 deletions src/components/TravelTimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { Box, Heading } from 'grommet'
import { addCash } from '../redux/actions/user'
import {
removeCargo,
setShipLocationName,
setShipLocationValue,
setShipLocation,
setDestination,
setShipTraveling,
setTravelDuration
Expand Down Expand Up @@ -83,8 +82,9 @@ const mapDispatchToProps = dispatch => ({
sellableItems.forEach(item => {
dispatch(removeCargo(item))
})
dispatch(setShipLocationName(destination.name))
dispatch(setShipLocationValue(destination.value))
dispatch(
setShipLocation({ name: destination.name, value: destination.value })
)
dispatch(setDestination(null))
dispatch(setShipTraveling(false))
},
Expand Down
20 changes: 7 additions & 13 deletions src/redux/actions/ship.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// * ACTION TYPES
const REMOVE_CARGO = 'REMOVE_CARGO'
const SET_DESTINATION = 'SET_DESTINATION'
const SET_SHIP_LOCATION_NAME = 'SET_SHIP_LOCATION_NAME'
const SET_SHIP_LOCATION_VALUE = 'SET_SHIP_LOCATION_VALUE'
const SET_SHIP_LOCATION = 'SET_SHIP_LOCATION'
const SET_SHIP_TRAVELING = 'SET_SHIP_TRAVELING'
const SET_TRAVEL_DURATION = 'SET_TRAVEL_DURATION'
const STORE_CARGO = 'STORE_CARGO'
Expand All @@ -15,14 +14,14 @@ export const removeCargo = item => ({
}
})

export const setShipLocationName = name => ({
type: SET_SHIP_LOCATION_NAME,
payload: { name }
export const setDestination = destination => ({
type: SET_DESTINATION,
payload: { destination }
})

export const setShipLocationValue = value => ({
type: SET_SHIP_LOCATION_VALUE,
payload: { value }
export const setShipLocation = location => ({
type: SET_SHIP_LOCATION,
payload: { location }
})

export const setShipTraveling = isShipTraveling => ({
Expand All @@ -43,11 +42,6 @@ export const storeCargo = (item, quantity) => ({
}
})

export const setDestination = destination => ({
type: SET_DESTINATION,
payload: { destination }
})

// * PROMISES

// * THUNKS
9 changes: 2 additions & 7 deletions src/redux/reducers/ship.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,10 @@ export default (state = shipDefaultState, action) => {
}
case 'SET_DESTINATION':
return { ...state, destination: action.payload.destination }
case 'SET_SHIP_LOCATION_NAME':
case 'SET_SHIP_LOCATION':
return {
...state,
location: { ...state.location, name: action.payload.name }
}
case 'SET_SHIP_LOCATION_VALUE':
return {
...state,
location: { ...state.location, value: action.payload.value }
location: action.payload.location
}
case 'SET_SHIP_TRAVELING':
return { ...state, isShipTraveling: action.payload.isShipTraveling }
Expand Down

0 comments on commit ecf00c8

Please sign in to comment.