Skip to content

Commit

Permalink
πŸ”€ Merge pull request #165 from alexlee-dev/feature/dissapearing-planets
Browse files Browse the repository at this point in the history
πŸ™ˆ Dissapearing Planets
  • Loading branch information
Alex Lee committed Sep 28, 2019
2 parents 87baec5 + 61edcea commit 0090788
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cypress/integration/Map-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,16 @@ describe('Map', () => {
cy.contains('TRAVEL').click()
// ! Assert that the new planet is traveled to
})

it("Should hide all 'g' components after traveling to the chosen planet.", () => {
const destinationPlanet = mockState.world.planets.find(
planet => planet.name !== mockState.ship.location.name
)
cy.contains(destinationPlanet.name).click()
cy.get('#travel-button').click()
cy.wait(1000)
cy.get('#map-root > svg')
.children()
.should('have.length', 0)
})
})
3 changes: 3 additions & 0 deletions src/components/TravelPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@material-ui/core'
import { connect } from 'react-redux'
import { instantTravel } from '../redux/actions/ship'
import { hidePlanets } from '../util/map'

const TravelPrompt = ({ destination, handleTravel, open, setOpen }) => {
const handleClose = () => setOpen(false)
Expand All @@ -27,6 +28,7 @@ const TravelPrompt = ({ destination, handleTravel, open, setOpen }) => {
Cancel
</Button>
<Button
id="travel-button"
onClick={() => handleTravel(destination, setOpen)}
color="primary"
>
Expand All @@ -48,6 +50,7 @@ const mapStateToProps = () => ({})

const mapDispatchToProps = dispatch => ({
handleTravel: (destination, setOpen) => {
hidePlanets()
dispatch(instantTravel(destination))
setOpen(false)
}
Expand Down
13 changes: 13 additions & 0 deletions src/util/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,16 @@ export const getHeight = selector =>
d3.select(selector).property('clientHeight')

export const getWidth = selector => d3.select(selector).property('clientWidth')

export const hidePlanets = () => {
let value = 1.0
const interval = setInterval(() => {
console.log({ value })
if (value <= 0) {
clearInterval(interval)
d3.selectAll('g').remove()
}
d3.selectAll('g').style('opacity', value - 0.05)
value -= 0.05
}, 100)
}

0 comments on commit 0090788

Please sign in to comment.