Skip to content

Commit

Permalink
Tour guide refactors (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
promarcussmith authored Feb 6, 2021
1 parent 897568f commit e2bd20f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 26 deletions.
33 changes: 33 additions & 0 deletions simplq/src/components/common/Tour/Tour.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { useState } from 'react';
import Tour from 'reactour';
import { enableScroll, disableScroll } from './ControlScroll';

export default (props) => {
const hasUserBeenOnTour = () => {
const tourStatus = localStorage.getItem('__user_been_on_tour__');
if (tourStatus === null) {
localStorage.setItem('__user_been_on_tour__', true);
return true;
}
return false;
};
const [tourOpen, setTourOpen] = useState(hasUserBeenOnTour());

const closeTour = () => setTourOpen(false);

return (
<Tour
showNavigation={false}
steps={props.toursteps}
showNavigationNumber={false}
showNumber={false}
showCloseButton={false}
isOpen={tourOpen}
rounded={10}
onRequestClose={closeTour}
onAfterOpen={disableScroll}
onBeforeClose={enableScroll}
getCurrentStep={props.stepChange}
/>
);
};
28 changes: 21 additions & 7 deletions simplq/src/components/pages/Admin/TourSteps.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import * as Sentry from '@sentry/react';

export const getToursteps = (screenInnerWidth) => {
const tourProperties = {
Expand Down Expand Up @@ -45,6 +46,7 @@ export const getToursteps = (screenInnerWidth) => {
alt="share queue arrow"
height="80"
width="120"
style={{ transform: 'rotate(-10deg)' }}
/>
) : null}
<div style={{ transform: 'rotate(-10deg)' }}>Share Queue</div>
Expand All @@ -62,11 +64,23 @@ export const getToursteps = (screenInnerWidth) => {
];
};

export const hasUserBeenOnTour = () => {
const tourStatus = localStorage.getItem('__user_been_on_tour__');
if (tourStatus === null) {
localStorage.setItem('__user_been_on_tour__', true);
return true;
export const stepChange = (stepNumber) => {
const leftArrow = document.querySelector("[data-tour-elem='left-arrow']");
const rightArrow = document.querySelector("[data-tour-elem='right-arrow']");

if (leftArrow && rightArrow) {
if (stepNumber === 0) {
leftArrow.childNodes[0].style.color = 'grey';
rightArrow.childNodes[0].style.color = 'white';
}
else if (stepNumber === 1) {
leftArrow.childNodes[0].style.color = 'white';
rightArrow.childNodes[0].style.color = 'grey';
}
}
return false;
};
else
{
Sentry.captureMessage("left-arrow or right-arrow selectors of reatTour package not found");
}

}
23 changes: 4 additions & 19 deletions simplq/src/components/pages/Admin/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React, { useState, useEffect, useCallback } from 'react';
import RefreshIcon from '@material-ui/icons/Refresh';
import CropFreeIcon from '@material-ui/icons/CropFree';
import { useAuth0 } from '@auth0/auth0-react';
import Tour from 'reactour';
import TokenList from './TokenList';
import { TokenRequestFactory, QueueRequestFactory } from '../../../api/requestFactory';
import ShareQueue from './ShareQueue';
Expand All @@ -14,9 +13,9 @@ import SidePanel from './AdminSidePanel';
import StandardButton from '../../common/Button';
import Ribbon from '../../common/Ribbon';
import QRCode from '../../common/Popup/QrCode';
import { disableScroll, enableScroll } from './ControlScroll';
import { getToursteps, hasUserBeenOnTour } from './TourSteps';
import { getToursteps, stepChange } from './TourSteps';
import useRequest from '../../../api/useRequest';
import Tour from '../../common/Tour/Tour';

const TIMEOUT = 10000;
let timeoutId;
Expand All @@ -28,13 +27,11 @@ export default (props) => {
const [queueName, setQueueName] = useState();
const [description, setDescription] = useState('');
const [showQrCodeModal, setShowQrCodeModal] = useState(false);
const [tourOpen, setTourOpen] = useState(hasUserBeenOnTour());

const [toursteps, setToursteps] = useState(getToursteps(window.innerHeight));
const { isAuthenticated } = useAuth0();
const { requestMaker } = useRequest();

const closeTour = () => setTourOpen(false);

const update = useCallback(() => {
clearTimeout(timeoutId);
requestMaker(QueueRequestFactory.get(queueId)).then((data) => {
Expand Down Expand Up @@ -123,19 +120,7 @@ export default (props) => {

return (
<div className={styles['admin-content']}>
<Tour
showNavigation={false}
steps={toursteps}
showNavigationNumber={false}
showNumber={false}
showCloseButton={false}
isOpen={tourOpen}
rounded={10}
onRequestClose={closeTour}
onAfterOpen={disableScroll}
onBeforeClose={enableScroll}
/>

<Tour toursteps={toursteps} stepChange={stepChange} />
<HeaderSection />
{isAuthenticated ? null : (
<Ribbon
Expand Down

0 comments on commit e2bd20f

Please sign in to comment.