From ecf00c8ba5a57af6f84ac0af6fbac0d44327219e Mon Sep 17 00:00:00 2001 From: alexlee-dev Date: Sat, 24 Aug 2019 16:39:23 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Convert=20setShipLocationN?= =?UTF-8?q?ame()=20+=20setShipLocationValue()=20to=20setShipLocation().?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 12 +++++------- src/components/TravelTimer.js | 8 ++++---- src/redux/actions/ship.js | 20 +++++++------------- src/redux/reducers/ship.js | 9 ++------- 4 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/App.js b/src/App.js index b4b81df..12a1fb1 100644 --- a/src/App.js +++ b/src/App.js @@ -2,7 +2,7 @@ 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' @@ -10,8 +10,8 @@ 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(() => { @@ -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)) } }) diff --git a/src/components/TravelTimer.js b/src/components/TravelTimer.js index 29024cc..352d17b 100644 --- a/src/components/TravelTimer.js +++ b/src/components/TravelTimer.js @@ -6,8 +6,7 @@ import { Box, Heading } from 'grommet' import { addCash } from '../redux/actions/user' import { removeCargo, - setShipLocationName, - setShipLocationValue, + setShipLocation, setDestination, setShipTraveling, setTravelDuration @@ -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)) }, diff --git a/src/redux/actions/ship.js b/src/redux/actions/ship.js index bdbd53a..e244a0a 100644 --- a/src/redux/actions/ship.js +++ b/src/redux/actions/ship.js @@ -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' @@ -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 => ({ @@ -43,11 +42,6 @@ export const storeCargo = (item, quantity) => ({ } }) -export const setDestination = destination => ({ - type: SET_DESTINATION, - payload: { destination } -}) - // * PROMISES // * THUNKS diff --git a/src/redux/reducers/ship.js b/src/redux/reducers/ship.js index f390170..c71fc6c 100644 --- a/src/redux/reducers/ship.js +++ b/src/redux/reducers/ship.js @@ -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 }