bcgov / aries-oca-bundles

aries-oca-bundles
Apache License 2.0
8 stars 20 forks source link

Skip at start of the tutorial prevents 2nd half from playing #62

Closed Gavinok closed 1 year ago

Gavinok commented 1 year ago

This PR resolves issue #61 when skip is selected all automatic tutorial playback is stopped unless the info icon is selected.

Gavinok commented 1 year ago

I have now moved the demo system over to use localStorage. However, I could not come up with a clean way to make use of useMemo since I needed to also manually allow users to skip the demo.

I had a working solution using a foundCookies (which used useMemo to get the state of the cookies) variable as well as a skipDemo variable but it over complicated the code since

I opted to simply check for cookies on initialization as the initial state for skipDemo and have a dedicated function to update that skipDemo to true and update the localStorage. This way we

amanji commented 1 year ago

I'm a bit confused here about the need to track all the different edge cases (and it might just be best to hop on a call).

Why don't we just have a single state that tracks the current progress of the tutorial?

I was thinking something along the lines of (and again point out if I'm overlooking anything):

In order to make this work you can use a useEffect hook to watch changes to the state and update the localStorage.

The useMemo in this case is just to load the current state out of localStorage and only ever gets run when the component mounts for the first time. If the 'end' state is loaded from localStorage then we don't run the demo.

Gavinok commented 1 year ago

I attempted to use useMemo like so

  // Track if we should skip the rest of the demo.
  const [skipDemo, setSkipDemo] = useState<boolean>(false);

   useMemo(() => {
    // Default value should be set based on the stored token in local storage
    setSkipDemo(localStorage.getItem('OCAExplorerSeenDemo') != null)
  }, [skipDemo])

  useEffect( () => {
    // update localStorage to reflect the skipDemo state
    if (skipDemo == true) {
      localStorage.setItem('OCAExplorerSeenDemo', 'true');
    }
  }, [skipDemo])

However the useMemo seems to prevent any updates going to skipDemo when the skip button is hit