Skip to content

Commit

Permalink
Merge aee8329 into 9e4541e
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Lee committed Aug 21, 2019
2 parents 9e4541e + aee8329 commit 3d63b5b
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 69 deletions.
2 changes: 1 addition & 1 deletion src/components/ItemTimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
const ItemTimer = ({ handleTimerStarted, handleTimerStopped, world }) => {
const { isTimerRunning } = world

let duration = moment.duration({ minutes: 10, seconds: 0 })
let duration = moment.duration({ minutes: 0, seconds: 5 })
const [timeLeft, setTimeLeft] = useState(
`${duration.minutes()} minutes ${duration.seconds()} seconds`
)
Expand Down
24 changes: 12 additions & 12 deletions src/redux/actions/ship.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
// * ACTION TYPES
const STORE_CARGO = 'STORE_CARGO'
const REMOVE_CARGO = 'REMOVE_CARGO'
const SET_SHIP_LOCATION_VALUE = 'SET_SHIP_LOCATION_VALUE'
const SET_SHIP_LOCATION_NAME = 'SET_SHIP_LOCATION_NAME'
const SET_SHIP_LOCATION_VALUE = 'SET_SHIP_LOCATION_VALUE'
const STORE_CARGO = 'STORE_CARGO'

// * ACTION GENERATORS
export const storeCargo = item => ({
type: STORE_CARGO,
payload: {
item
}
})

export const removeCargo = item => ({
type: REMOVE_CARGO,
payload: {
item
}
})

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

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

export const setShipLocationName = name => ({
type: SET_SHIP_LOCATION_NAME,
payload: { name }
export const storeCargo = item => ({
type: STORE_CARGO,
payload: {
item
}
})

// * PROMISES
Expand Down
26 changes: 13 additions & 13 deletions src/redux/actions/world.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
// * ACTION TYPES
const SET_TIMER_RUNNING = 'SET_TIMER_RUNNING'
const REMOVE_ITEM = 'REMOVE_ITEM'
const SET_PLANETS = 'SET_PLANETS'
const CLEAR_ITEMS = 'CLEAR_ITEMS'
const REFRESH_ITEMS = 'REFRESH_ITEMS'
const REMOVE_ITEM = 'REMOVE_ITEM'
const SET_PLANETS = 'SET_PLANETS'
const SET_TIMER_RUNNING = 'SET_TIMER_RUNNING'

// * ACTION GENERATORS
export const setPlanets = planets => ({
type: SET_PLANETS,
payload: { planets }
})
export const clearItems = () => ({ type: CLEAR_ITEMS })

export const setTimerRunning = isTimerRunning => ({
type: SET_TIMER_RUNNING,
payload: { isTimerRunning }
})
export const refreshItems = () => ({ type: REFRESH_ITEMS })

export const removeItem = item => ({
type: REMOVE_ITEM,
Expand All @@ -23,9 +17,15 @@ export const removeItem = item => ({
}
})

export const clearItems = () => ({ type: CLEAR_ITEMS })
export const setPlanets = planets => ({
type: SET_PLANETS,
payload: { planets }
})

export const refreshItems = () => ({ type: REFRESH_ITEMS })
export const setTimerRunning = isTimerRunning => ({
type: SET_TIMER_RUNNING,
payload: { isTimerRunning }
})

// * PROMISES

Expand Down
18 changes: 7 additions & 11 deletions src/redux/reducers/ship.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,23 @@ const shipDefaultState = {

export default (state = shipDefaultState, action) => {
switch (action.type) {
case 'SET_SHIP_LOCATION_VALUE':
case 'REMOVE_CARGO':
return {
...state,
location: { ...state.location, value: action.payload.value }
cargo: state.cargo.filter(item => item.id !== action.payload.item.id)
}
case 'SET_SHIP_LOCATION_NAME':
return {
...state,
location: { ...state.location, name: action.payload.name }
}
case 'SET_SHIP_LOCATION_VALUE':
return {
...state,
location: { ...state.location, value: action.payload.value }
}
case 'STORE_CARGO':
return { ...state, cargo: [...state.cargo, action.payload.item] }
case 'REMOVE_CARGO':
const itemIndex = state.cargo.findIndex(
item => item.id === action.payload.item.id
)

const newCargo = Array.from(state.cargo)
newCargo.splice(itemIndex, 1)

return { ...state, cargo: newCargo }
default:
return state
}
Expand Down
3 changes: 1 addition & 2 deletions src/redux/reducers/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const uiDefaultState = {
export default (state = uiDefaultState, action) => {
switch (action.type) {
case 'SET_VIEW':
const { view } = action.payload
return { ...state, view }
return { ...state, view: action.payload.view }
default:
return state
}
Expand Down
50 changes: 20 additions & 30 deletions src/redux/reducers/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,41 @@ const worldDefaultState = {
export default (state = worldDefaultState, action) => {
switch (action.type) {
case 'CLEAR_ITEMS':
const newPlanets = [...state.planets]

newPlanets.forEach(planet => {
planet.items = []
})

return { ...state, planets: newPlanets }
return {
...state,
planets: state.planets.map(planet => ({ ...planet, items: [] }))
}
case 'REFRESH_ITEMS':
const additionalPlanets = [...state.planets]

additionalPlanets.forEach(planet => {
planet.items = generateItems()
})

return { ...state, planets: additionalPlanets }
case 'SET_PLANETS':
const { planets } = action.payload

return { ...state, planets }
case 'SET_TIMER_RUNNING':
const { isTimerRunning } = action.payload

return { ...state, isTimerRunning }
return {
...state,
planets: state.planets.map(planet => ({
...planet,
items: generateItems(state.planets)
}))
}
case 'REMOVE_ITEM':
const { item } = action.payload

const updatedPlanets = []

state.planets.forEach(planet => {
const updatedPlanets = state.planets.map(planet => {
const { isHomePlanet, items, location, name } = planet
const planetContainsItem = items.includes(item)
if (planetContainsItem) {
const newPlanetObj = {

if (planet.items.includes(item)) {
return {
isHomePlanet,
items: items.filter(currentItem => item !== currentItem),
location,
name
}
updatedPlanets.push(newPlanetObj)
} else {
updatedPlanets.push(planet)
return planet
}
})

return { ...state, planets: updatedPlanets }
case 'SET_PLANETS':
return { ...state, planets: action.payload.planets }
case 'SET_TIMER_RUNNING':
return { ...state, isTimerRunning: action.payload.isTimerRunning }
default:
return state
}
Expand Down

0 comments on commit 3d63b5b

Please sign in to comment.