Skip to content

Commit

Permalink
🐛 fixing guided tour not saving to the storage (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoscar authored Apr 25, 2022
1 parent a43f3f0 commit 941fd22
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions web/src/components/GuidedTour/useGuidedTour.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useTour} from '@reactour/tour';
import {delay as delayFn} from 'lodash';
import {useEffect} from 'react';
import {useEffect, useState} from 'react';
import GuidedTourService, {GuidedTours} from '../../services/GuidedTourService';
import HomeStepList from './homeStepList';
import AssertionStepList from './assertionStepList';
Expand All @@ -15,10 +15,12 @@ const StepListMap = {
};

const useGuidedTour = (tour: GuidedTours, delay = 500) => {
const [isLoaded, setIsLoaded] = useState(false);
const tourFn = useTour();
const {setCurrentStep, setIsOpen, setSteps} = tourFn;
const {setCurrentStep, setIsOpen, setSteps, isOpen} = tourFn;

useEffect(() => {
setIsLoaded(false);
setSteps(StepListMap[tour]);
}, [tour, setSteps]);

Expand All @@ -28,10 +30,15 @@ const useGuidedTour = (tour: GuidedTours, delay = 500) => {
delayFn(() => {
setCurrentStep(0);
setIsOpen(true);
setIsLoaded(true);
}, delay);
}
}, [delay, setCurrentStep, setIsOpen, tour]);

useEffect(() => {
if (!isOpen && isLoaded) GuidedTourService.save(tour);
}, [isLoaded, isOpen, tour]);

return tourFn;
};

Expand Down

0 comments on commit 941fd22

Please sign in to comment.