Interactive interface for browsing global, full-resolution satellite imagery
Make esc button leave tour #2034
Benjamin King85eda6d94f2a
diff --git a/web/js/app.js b/web/js/app.jsindex 94b4bf035..5c69ea991 100644--- a/web/js/app.js+++ b/web/js/app.js@@ -89,11 +89,11 @@ class App extends React.Component {}componentDidMount() {- document.addEventListener('keypress', this.handleKeyPress);+ document.addEventListener('keydown', this.handleKeyPress);}componentWillUnmount() {- document.removeEventListener('keypress', this.handleKeyPress);+ document.removeEventListener('keydown', this.handleKeyPress);}render() {diff --git a/web/js/components/tour/modal-tour-in-progress.js b/web/js/components/tour/modal-tour-in-progress.jsindex 2f348a359..bcaa69e4b 100644--- a/web/js/components/tour/modal-tour-in-progress.js+++ b/web/js/components/tour/modal-tour-in-progress.js@@ -7,24 +7,7 @@ class ModalInProgress extends React.Component {constructor(props) {super(props);- this.escFunction = this.escFunction.bind(this);}-- componentDidMount() {- document.addEventListener('keydown', this.escFunction, false);- }-- componentWillUnmount() {- document.removeEventListener('keydown', this.escFunction, false);- }-- // Use custom escFunction since tabIndex prevents escape key use on loading WV- escFunction(e) {- if (e.keyCode === 27 && this.props.modalInProgress) {- this.props.endTour();- }- }-componentDidUpdate() {if (this.refs.stepContent) this.refs.stepContent.parentNode.scrollTop = 0;}diff --git a/web/js/components/tour/modal-tour-start.js b/web/js/components/tour/modal-tour-start.jsindex 507e4ba98..5ae671fee 100644--- a/web/js/components/tour/modal-tour-start.js+++ b/web/js/components/tour/modal-tour-start.js@@ -23,17 +23,14 @@ class ModalStart extends React.Component {this.setWrapperRef = this.setWrapperRef.bind(this);this.handleClickOutside = this.handleClickOutside.bind(this);this.handleCheck = this.handleCheck.bind(this);- this.escFunction = this.escFunction.bind(this);}componentDidMount() {document.addEventListener('mousedown', this.handleClickOutside);- document.addEventListener('keydown', this.escFunction, false);}componentWillUnmount() {document.removeEventListener('mousedown', this.handleClickOutside);- document.removeEventListener('keydown', this.escFunction, false);}// Set a reference to the inner div for checking clicks outside of the scrollbar@@ -41,12 +38,6 @@ class ModalStart extends React.Component {this.wrapperRef = node;}- // Use custom escFunction since tabIndex prevents escape key use on loading WV- escFunction(e) {- if (e.keyCode === 27 && this.props.modalStart) {- this.props.toggleModalStart(e);- }- }// Use custom clickOutside function since we contained the clickable area with// CSS to have a cleaner looking scrollbardiff --git a/web/js/modules/key-press/actions.js b/web/js/modules/key-press/actions.jsindex f19769017..8ea047247 100644--- a/web/js/modules/key-press/actions.js+++ b/web/js/modules/key-press/actions.js@@ -1,4 +1,5 @@import { KEY_PRESS_ACTION as ANIMATION_KEY_PRESS_ACTION } from '../animation/constants';+import { TOUR_KEY_PRESS_CLOSE } from '../tour/constants';/*** Function to dispatch actions@@ -9,7 +10,7 @@ import { KEY_PRESS_ACTION as ANIMATION_KEY_PRESS_ACTION } from '../animation/con*/export function keyPress(keyCode) {return (dispatch, getState) => {- const { modal, animation } = getState();+ const { modal, animation, tour } = getState();if (animation.isActive && !modal.isOpen) {// can get more specific modal.key !== "LAYER_PICKER_COMPONENT"dispatch({@@ -17,5 +18,10 @@ export function keyPress(keyCode) {keyCode});}+ if (tour.active && keyCode === 27) {+ dispatch({+ type: TOUR_KEY_PRESS_CLOSE+ });+ }};}diff --git a/web/js/modules/tour/constants.js b/web/js/modules/tour/constants.jsindex c6cae39d9..d96e9ec93 100644--- a/web/js/modules/tour/constants.js+++ b/web/js/modules/tour/constants.js@@ -2,7 +2,7 @@ import Tour from '../../containers/tour';export const START = 'TOUR/START_TOUR';export const UPDATE_SELECTED = 'TOUR/UPDATE_SELECTED_STORY';export const END_TOUR = 'TOUR/END_TOUR';-+export const TOUR_KEY_PRESS_CLOSE = 'TOUR/TOUR_KEY_PRESS_CLOSE';const customModalProps = {backdrop: false,CompletelyCustomModal: Tour,diff --git a/web/js/modules/tour/reducers.js b/web/js/modules/tour/reducers.jsindex dc9f72989..97a57cf28 100644--- a/web/js/modules/tour/reducers.js+++ b/web/js/modules/tour/reducers.js@@ -1,4 +1,4 @@-import { START, UPDATE_SELECTED, END_TOUR } from './constants';+import { START, UPDATE_SELECTED, END_TOUR, TOUR_KEY_PRESS_CLOSE } from './constants';import { assign as lodashAssign } from 'lodash';const INITIAL_STATE = {@@ -13,6 +13,11 @@ export default function tourReducer(state = INITIAL_STATE, action) {selected: '',active: false});+ case TOUR_KEY_PRESS_CLOSE:+ return lodashAssign({}, state, {+ selected: '',+ active: false+ });case START:return lodashAssign({}, state, {selected: '',