github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/hooks/navigateUserIntroPages.hook.ts (about)

     1  import { useEffect } from 'react';
     2  import { useAppDispatch, useAppSelector } from '@webapp/redux/hooks';
     3  import {
     4    loadCurrentUser,
     5    selectCurrentUser,
     6  } from '@webapp/redux/reducers/user';
     7  import { useHistory } from 'react-router-dom';
     8  import { PAGES } from '@webapp/pages/constants';
     9  
    10  export default function useNavigateUserIntroPages() {
    11    const dispatch = useAppDispatch();
    12    const currentUser = useAppSelector(selectCurrentUser);
    13    const history = useHistory();
    14  
    15    // loading user on page mount
    16    useEffect(() => {
    17      dispatch(loadCurrentUser());
    18    }, []);
    19    // there are cases when user doesn't exist on page mount
    20    // but appears after submitting login/signup form
    21    useEffect(() => {
    22      if (currentUser) {
    23        history.push(PAGES.CONTINOUS_SINGLE_VIEW);
    24      }
    25    }, [currentUser]);
    26  }