Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

prevent distraction mode firing when product picker is open, close modals on ESC, refactor to clean up conditionals, close anim widget on ESC

Ed Platoe9e2945efb84
diff --git a/web/js/modules/animation/reducers.js b/web/js/modules/animation/reducers.js
index 219495147..c6f82d6b9 100644
--- a/web/js/modules/animation/reducers.js
+++ b/web/js/modules/animation/reducers.js
@@ -93,6 +93,13 @@ export function animationReducer(state = defaultState, action) {
isPlaying: !state.isPlaying,
});
}
+ if (action.keyCode === 27) {
+ return lodashAssign({}, state, {
+ isActive: false,
+ gifActive: false,
+ isPlaying: false,
+ });
+ }
return state;
default:
diff --git a/web/js/modules/key-press/actions.js b/web/js/modules/key-press/actions.js
index a5ce1de44..c5e801129 100644
--- a/web/js/modules/key-press/actions.js
+++ b/web/js/modules/key-press/actions.js
@@ -16,28 +16,34 @@ export default function keyPress(keyCode, shiftKey, ctrlOrCmdKey) {
const {
modal, animation, tour, ui,
} = getState();
- const modalIsOpen = modal.isOpen;
+ const {
+ id,
+ isOpen,
+ } = modal;
const { isDistractionFreeModeActive } = ui;
- if (animation.isActive && !modalIsOpen) {
- // can get more specific modal.key !== "LAYER_PICKER_COMPONENT"
- dispatch({
- type: ANIMATION_KEY_PRESS_ACTION,
- keyCode,
- });
- }
+ const isProductPickerOpen = isOpen && id === 'LAYER_PICKER_COMPONENT';
if (tour.active && keyCode === 27) {
dispatch({
type: TOUR_KEY_PRESS_CLOSE,
});
- }
- if (!ctrlOrCmdKey && shiftKey && keyCode === 68) {
- dispatch({ type: TOGGLE_DISTRACTION_FREE_MODE });
- if (!isDistractionFreeModeActive && modalIsOpen) {
- dispatch({ type: CLOSE_MODAL });
+ } else if (!isProductPickerOpen) {
+ if (animation.isActive) {
+ dispatch({
+ type: ANIMATION_KEY_PRESS_ACTION,
+ keyCode,
+ });
+ } else if (!ctrlOrCmdKey && shiftKey && keyCode === 68) {
+ dispatch({ type: TOGGLE_DISTRACTION_FREE_MODE });
+ if (!isDistractionFreeModeActive && isOpen) {
+ dispatch({ type: CLOSE_MODAL });
+ }
+ } else if (keyCode === 27) {
+ if (isDistractionFreeModeActive) {
+ dispatch({ type: TOGGLE_DISTRACTION_FREE_MODE });
+ } else {
+ dispatch({ type: CLOSE_MODAL });
+ }
}
}
- if (isDistractionFreeModeActive && keyCode === 27) {
- dispatch({ type: TOGGLE_DISTRACTION_FREE_MODE });
- }
};
}