Interactive interface for browsing global, full-resolution satellite imagery
remove placeholder elements on tour completion
Jason Kent67bad090cdc0
diff --git a/web/js/components/tour/joyride-wrapper.js b/web/js/components/tour/joyride-wrapper.jsindex a84962938..24f2c8e82 100644--- a/web/js/components/tour/joyride-wrapper.js+++ b/web/js/components/tour/joyride-wrapper.js@@ -1,21 +1,20 @@-import React, { useState, useEffect } from 'react';+import React, { useEffect } from 'react';// import { connect } from 'react-redux';import PropTypes from 'prop-types';import Joyride from 'react-joyride';-function JoyrideWrapper ({ tourSteps, currentTourStep, map }) {- const currentStepObj = tourSteps[currentTourStep - 1];- const joyrideProps = (currentStepObj || {}).joyride;- if (!joyrideProps) {- return null;- }+const placeholderElements = [];+function JoyrideWrapper ({+ tourSteps, currentTourStep, map, tourComplete,+}) {+ const currentStepObj = tourSteps[currentTourStep - 1];const {continuous,disableOverlayClose,spotlightClicks,steps,- } = joyrideProps;+ } = (currentStepObj || {}).joyride || {};const styleOptions = {arrowColor: '#ccc',@@ -29,61 +28,56 @@ function JoyrideWrapper ({ tourSteps, currentTourStep, map }) {zIndex: 1050,};- const [joyrideState, setJoyrideState] = useState({});- // const [overlayTarget, setOverlayTarget] = useState(false);-- // useEffect(() => {- // if (overlayTarget) {- // overlayTarget.remove();- // setOverlayTarget(false);- // }- // }, [currentTourStep]);+ // const [joyrideState, setJoyrideState] = useState({});useEffect(() => {- const { step } = joyrideState;- if (map && step && step.targetCoordinates) {- const id = step.target.substr(1, step.target.length);- const placeholderEl = document.querySelector(id) || document.createElement('span');- const { topLeft, bottomRight } = step.targetCoordinates;- let [x1, y1] = map.getPixelFromCoordinate(topLeft) || [0, 0];- let [x2, y2] = map.getPixelFromCoordinate(bottomRight) || [0, 0];- x1 = x1.toFixed(0);- y1 = y1.toFixed(0);- x2 = x2.toFixed(0);- y2 = y2.toFixed(0);- placeholderEl.id = id;- placeholderEl.style.position = 'absolute';- placeholderEl.style.top = `${y1}px`;- placeholderEl.style.left = `${x1}px`;- placeholderEl.style.height = `${x2 - x1}px`;- placeholderEl.style.width = `${y2 - y1}px`;- placeholderEl.style.backgroundColor = 'rgba(255, 0, 0, 0.25)';- placeholderEl.style.zIndex = '0';- placeholderEl.style.pointerEvents = 'none';+ (steps || []).forEach((step) => {+ const { target, targetCoordinates } = step || {};+ const existingEl = !document.querySelector(target);- if (!document.querySelector(step.target)) {+ if (map && target && targetCoordinates && existingEl) {+ const placeholderEl = document.createElement('span');+ const { topLeft, bottomRight } = targetCoordinates;+ let [x1, y1] = map.getPixelFromCoordinate(topLeft) || [0, 0];+ let [x2, y2] = map.getPixelFromCoordinate(bottomRight) || [0, 0];+ x1 = x1.toFixed(0);+ y1 = y1.toFixed(0);+ x2 = x2.toFixed(0);+ y2 = y2.toFixed(0);+ placeholderEl.id = target.substr(1, target.length);+ placeholderEl.style.position = 'absolute';+ placeholderEl.style.top = `${y1}px`;+ placeholderEl.style.left = `${x1}px`;+ placeholderEl.style.height = `${y2 - y1}px`;+ placeholderEl.style.width = `${x2 - x1}px`;+ placeholderEl.style.backgroundColor = 'rgba(255, 0, 0, 0.25)';+ placeholderEl.style.zIndex = '0';+ placeholderEl.style.pointerEvents = 'none';document.querySelector('body').appendChild(placeholderEl);- // setOverlayTarget(placeholderEl);+ placeholderElements.push(placeholderEl);}- }- },+ });+ }, [currentTourStep],);- const joyrideStateCallback = (jState) => {- console.log(jState);- setJoyrideState(jState);- };+ // When tour is complete, remove all placeholder elements+ useEffect(() => {+ if (tourComplete) {+ placeholderElements.forEach((element) => element.remove());+ }+ });- return !steps ? null : (+ return (<Joyride- steps={steps}+ steps={steps || []}continuous={continuous}spotlightClicks={spotlightClicks}disableOverlayClose={disableOverlayClose}styles={{ options: styleOptions }}- callback={joyrideStateCallback}+ // callback={setJoyrideState}disableScrolling+ debug/>);}@@ -101,5 +95,6 @@ export default JoyrideWrapper;JoyrideWrapper.propTypes = {currentTourStep: PropTypes.number,map: PropTypes.object,+ tourComplete: PropTypes.bool,tourSteps: PropTypes.array,};diff --git a/web/js/containers/tour.js b/web/js/containers/tour.jsindex d783efe87..619783838 100644--- a/web/js/containers/tour.js+++ b/web/js/containers/tour.js@@ -421,6 +421,7 @@ class Tour extends React.Component {currentTourStep={currentStep}tourSteps={currentStory.steps}map={map.ui.selected}+ tourComplete={!modalInProgress}/>)}{modalStart